Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fd6d89567 | ||
|
|
cddfeba266 |
@@ -5,7 +5,7 @@
|
||||
// exempt from that, and said so. Every build module, test step or not, must also hold a test that calls
|
||||
// conformance.LeftRunning with its own start sweep, so a step a previous process left running is ended at its start
|
||||
// (issue 1890), and one that calls conformance.Passing, so a step whose network did not answer is said as a transport fault
|
||||
// (issue 1748), and one that calls conformance.StepEnds, so its steps can say a pipeline step's end (design 47 G §24). Its manifest asks the capability seat-settle-delay (ADR 0664 §5).
|
||||
// (issue 1748). Its manifest asks the capability seat-settle-delay (ADR 0664 §5).
|
||||
package failurekit
|
||||
|
||||
import (
|
||||
@@ -91,25 +91,6 @@ func Judge(root string) ([]Judged, error) {
|
||||
refused = append(refused, fmt.Sprintf("it claims %s, and no test of it calls conformance.LeftRunning "+
|
||||
"(mesh-build-go buildstep/conformance): run the kit's left-running case with the module's own start sweep (issue 1890)", seat))
|
||||
}
|
||||
// A-489b: every build module is asked pipeline steps, so every one runs the case that its steps can say a step's end: without a
|
||||
// SayStep every step ask is refused live ("this build module says no step's end"), as mesh-build-node's was.
|
||||
ends, err := runsTheKit(dir, "conformance.StepEnds(")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
counts, err := runsTheKit(dir, "conformance.RunsCounted(")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !counts {
|
||||
// A-489c
|
||||
refused = append(refused, fmt.Sprintf("it claims %s, and no test of it calls conformance.RunsCounted "+
|
||||
"(mesh-delivery-sdk steprun/conformance): run the kit's case that its puller counts the runs that started, not the bus's deliveries (A-489a)", seat))
|
||||
}
|
||||
if !ends {
|
||||
refused = append(refused, fmt.Sprintf("it claims %s, and no test of it calls conformance.StepEnds "+
|
||||
"(mesh-delivery-sdk steprun/conformance): run the kit's step-ends case with the module's own steps (design 47 G §24)", seat))
|
||||
}
|
||||
// Every build module meets the network (a fetch, a download, an install, a publish), so every one runs the passing case: its
|
||||
// steps say a network that did not answer as a transport fault the bus gives the ask again for (ADR 0664, issue 1748).
|
||||
says, err := runsTheKit(dir, "conformance.Passing(")
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func TestABuildModuleWithATestStepMustRunTheKit(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
const imp = "package main\n\nimport \"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun/conformance\"\n\n"
|
||||
const sweep = "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\nfunc TestPassing(t *testing.T) { conformance.Passing(t, nil, nil) }\nfunc TestEnds(t *testing.T) { conformance.StepEnds(t, steprun.AskSteps{}) }\nfunc TestCounted(t *testing.T) { conformance.RunsCounted(t, nil) }\n"
|
||||
const sweep = "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\nfunc TestPassing(t *testing.T) { conformance.Passing(t, nil, nil) }\n"
|
||||
kit := imp + "func TestKit(t *testing.T) { conformance.Run(t, conformance.GoTest, nil) }\n" + sweep
|
||||
for path, body := range map[string]string{
|
||||
"modules/a/module.json": `{"claims":[{"name":"node-build-a"}],"tools":["build_a_fetch","build_a_test"]}`,
|
||||
@@ -30,10 +30,6 @@ func TestABuildModuleWithATestStepMustRunTheKit(t *testing.T) {
|
||||
"modules/h/cmd/h/kit_test.go": imp + "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\n",
|
||||
"modules/i/module.json": `{"claims":[{"name":"node-build-i"}],"capabilities":["other"],"tools":["build_i_build"]}`, // the whole kit, and no seat-settle-delay
|
||||
"modules/i/cmd/i/kit_test.go": imp + sweep,
|
||||
"modules/j/module.json": `{"claims":[{"name":"node-build-j"}],"capabilities":["seat-settle-delay"],"tools":["build_j_build"]}`, // the rest of the kit, and no step-ends case
|
||||
"modules/j/cmd/j/kit_test.go": imp + "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\nfunc TestPassing(t *testing.T) { conformance.Passing(t, nil, nil) }\nfunc TestCounted(t *testing.T) { conformance.RunsCounted(t, nil) }\n",
|
||||
"modules/k/module.json": `{"claims":[{"name":"node-build-k"}],"capabilities":["seat-settle-delay"],"tools":["build_k_build"]}`, // no runs-counted case
|
||||
"modules/k/cmd/k/kit_test.go": imp + "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\nfunc TestPassing(t *testing.T) { conformance.Passing(t, nil, nil) }\nfunc TestEnds(t *testing.T) { conformance.StepEnds(t, steprun.AskSteps{}) }\n",
|
||||
"modules/e/module.json": `{"claims":[{"name":"node-build-e"}],"tools":["build_e_test"]}`,
|
||||
"modules/e/cmd/e/kit.go": kit, // not a test file
|
||||
} {
|
||||
@@ -49,9 +45,9 @@ func TestABuildModuleWithATestStepMustRunTheKit(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := map[string]string{"a": "refused", "b": "passes", "c": "exempt", "e": "refused", "f": "refused", "g": "refused", "h": "refused", "i": "refused", "j": "refused", "k": "refused"}
|
||||
want := map[string]string{"a": "refused", "b": "passes", "c": "exempt", "e": "refused", "f": "refused", "g": "refused", "h": "refused", "i": "refused"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("judged %+v, want a, b, c, e, f, g, h, i, j and k", got)
|
||||
t.Fatalf("judged %+v, want a, b, c, e, f, g, h and i", got)
|
||||
}
|
||||
for _, j := range got {
|
||||
is := "passes"
|
||||
|
||||
@@ -91,7 +91,7 @@ func (m *Module) Puller(steps []StepTool, source steprun.AskSource) *steprun.Pul
|
||||
if m.SayEvent != nil {
|
||||
say = steprun.SayOn(sdkstep.AskGo, m.Node, m.SayEvent)
|
||||
}
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskGo, Say: say, Callers: m.Callers, Prior: steprun.PriorRuns(m.ReadSteps.Get), Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskGo, Say: say, Callers: m.Callers, Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
Capacity: capacity, SettingsFile: settings, WatchConfig: watch, CoresPerStep: cores, BuildHours: hours, Logf: m.Say, Has: m.Has,
|
||||
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) {
|
||||
if err := m.Check(ctx); err != nil {
|
||||
|
||||
@@ -56,19 +56,3 @@ func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A-489b, design 47 G §24: the module's own steps can say a pipeline step's end, or
|
||||
// every step ask the runner sends it is refused ("this build module says no step's end"), as the first live pipeline met.
|
||||
func TestTheStepsCanSayAStepsEnd(t *testing.T) {
|
||||
conformance.StepEnds(t, (&Module{Node: "kitnode"}).askSteps(nil))
|
||||
}
|
||||
|
||||
// A-489c (A-489a): the module's puller counts the runs its steps state says started, not the bus's deliveries (an ask given back before
|
||||
// it ran is no run), so the poison rule never ends an ask that never ran.
|
||||
func TestThePullerCountsRunsThatStarted(t *testing.T) {
|
||||
conformance.RunsCounted(t, func(read func(string) (json.RawMessage, error)) *steprun.Puller {
|
||||
m := &Module{Node: "kitnode", Capacity: func() int { return 1 }}
|
||||
m.ReadSteps = StateRead{Get: read}
|
||||
return m.Puller(nil, steprun.NewFakeAsks())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -195,16 +195,6 @@ func TestTheModuleInvokesTheArtifactSeatsVerbsAndWritesNoStore(t *testing.T) {
|
||||
if !slices.Contains(m.Consumes, "mesh-conditions.findings-asked") {
|
||||
t.Errorf("consumes %v lack mesh-conditions.findings-asked", m.Consumes)
|
||||
}
|
||||
// Design 47 G A-488a, A-488b: its runtime follows the seat list, so the module consumes the seat's two events (which makes its
|
||||
// durable consumer) and invokes the verb that reads the list.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions", m.Invokes)
|
||||
}
|
||||
// Not a foundation part, it asks its finding stream in requires, by the template events (design 47 G §529, A-30), and
|
||||
// declares no stream of that name.
|
||||
for _, st := range m.Streams {
|
||||
|
||||
@@ -33,9 +33,7 @@
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-conditions.findings-asked",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
"mesh-conditions.findings-asked"
|
||||
],
|
||||
"invokes": [
|
||||
"seat:mesh-hand-acts.hand-act",
|
||||
@@ -48,7 +46,6 @@
|
||||
"seat:mesh-wants.input",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions",
|
||||
"seat:mesh-catalog.entry"
|
||||
],
|
||||
"config": {
|
||||
|
||||
@@ -31,20 +31,9 @@ func (m *Module) askSteps(steps []StepTool) steprun.AskSteps {
|
||||
Fetch: byName["build_image_fetch"], Build: byName["build_image_build"], Copy: byName["build_image_copy"],
|
||||
Release: func(ws string) error { return m.spaces().Release(ws) },
|
||||
Logf: m.Say,
|
||||
Node: m.Node,
|
||||
SayStep: m.sayStep(),
|
||||
}
|
||||
}
|
||||
|
||||
// sayStep says a step ask's end on this node's subject of the seat (design 47 G §24): an image has no lint, unit or integration
|
||||
// step (§328), so none is asked of this seat, but the steps of every build module can say their ends, which the kit holds.
|
||||
func (m *Module) sayStep() func(sdkstep.StepEnded) error {
|
||||
if m.SayStep != nil {
|
||||
return m.SayStep
|
||||
}
|
||||
return steprun.SayStepOn(sdkstep.AskImage, m.Node, stdio.SeatPublish)
|
||||
}
|
||||
|
||||
// Puller is the module's pull of its seat's asks, on source (the runtime's seat pull when nil).
|
||||
func (m *Module) Puller(steps []StepTool, source steprun.AskSource) *steprun.Puller {
|
||||
if source == nil {
|
||||
@@ -80,7 +69,7 @@ func (m *Module) Puller(steps []StepTool, source steprun.AskSource) *steprun.Pul
|
||||
if m.SayEvent != nil {
|
||||
say = steprun.SayOn(sdkstep.AskImage, m.Node, m.SayEvent)
|
||||
}
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskImage, Say: say, Callers: m.Callers, Prior: steprun.PriorRuns(m.ReadSteps.Get), Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskImage, Say: say, Callers: m.Callers, Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
Capacity: capacity, SettingsFile: settings, WatchConfig: watch, CoresPerStep: cores, BuildHours: hours, Eligible: m.Eligible, Logf: m.Say,
|
||||
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) {
|
||||
if err := m.Check(ctx); err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestTheModuleInvokesTheImageSeatAndHoldsNoRegistry(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := []string{"seat:mesh-hand-acts.hand-act", "seat:container-image-registry.publish", "seat:container-image-registry.publish-part",
|
||||
"seat:container-image-registry.mirror", "seat:mesh-module-assigner.assignments", "seat:mesh-catalog.module", "seat:mesh-catalog.seat-definitions"}; !slices.Equal(m.Invokes, want) {
|
||||
"seat:container-image-registry.mirror", "seat:mesh-module-assigner.assignments", "seat:mesh-catalog.module"}; !slices.Equal(m.Invokes, want) {
|
||||
t.Errorf("invokes = %v, want %v", m.Invokes, want)
|
||||
}
|
||||
// The seat's outcomes a copy waits on; the version comes in the ask, so version.numbered is not heard (design 47 G §413).
|
||||
@@ -32,7 +32,6 @@ func TestTheModuleInvokesTheImageSeatAndHoldsNoRegistry(t *testing.T) {
|
||||
for _, e := range OutcomeEvents {
|
||||
consumes = append(consumes, "container-image-registry."+e)
|
||||
}
|
||||
consumes = append(consumes, "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed") // the seat list, A-488a
|
||||
if !slices.Equal(m.Consumes, consumes) {
|
||||
t.Errorf("consumes = %v, want %v", m.Consumes, consumes)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
@@ -45,19 +44,3 @@ func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A-489b, design 47 G §24: the module's own steps can say a pipeline step's end, or
|
||||
// every step ask the runner sends it is refused ("this build module says no step's end"), as the first live pipeline met.
|
||||
func TestTheStepsCanSayAStepsEnd(t *testing.T) {
|
||||
conformance.StepEnds(t, (&Module{Node: "kitnode"}).askSteps(nil))
|
||||
}
|
||||
|
||||
// A-489c (A-489a): the module's puller counts the runs its steps state says started, not the bus's deliveries (an ask given back before
|
||||
// it ran is no run), so the poison rule never ends an ask that never ran.
|
||||
func TestThePullerCountsRunsThatStarted(t *testing.T) {
|
||||
conformance.RunsCounted(t, func(read func(string) (json.RawMessage, error)) *steprun.Puller {
|
||||
m := &Module{Node: "kitnode", Capacity: func() int { return 1 }}
|
||||
m.ReadSteps = StateRead{Get: read}
|
||||
return m.Puller(nil, steprun.NewFakeAsks())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -113,16 +113,6 @@ func TestWorkAndStoreDirectoriesLieOutsideTheHome(t *testing.T) {
|
||||
// and the registry's address is bound into a file of the home that the program reads.
|
||||
func TestManifestKeepsItsStatesClaimsItsBuildSeatAndDeclaresItsHealthTool(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
// Design 47 G A-488a, A-488b: its runtime follows the seat list, so the module consumes the seat's two events (which makes its
|
||||
// durable consumer) and invokes the verb that reads the list.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions", m.Invokes)
|
||||
}
|
||||
states := []string{}
|
||||
for _, s := range m.State {
|
||||
states = append(states, s.Name)
|
||||
|
||||
@@ -28,8 +28,6 @@ type Module struct {
|
||||
// SayEvent publishes an event of the image build seat on a seat subject (stdio.SeatPublish; nil says none, a test's): the
|
||||
// puller's ask-taken, step-progress and step-ended (design 47 G §496, §602).
|
||||
SayEvent func(subject string, body any, id string) error
|
||||
// SayStep says a step ask's end (steprun.AskSteps.SayStep); the seat's publish on this node when nil (a test's own).
|
||||
SayStep func(sdkstep.StepEnded) error
|
||||
|
||||
Node string
|
||||
// RecordAct writes an act in the hand-act log of the seat mesh-hand-acts (§463, §480): a drop writes it first.
|
||||
|
||||
@@ -68,14 +68,11 @@
|
||||
"seat:container-image-registry.publish-part",
|
||||
"seat:container-image-registry.mirror",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions"
|
||||
"seat:mesh-catalog.module"
|
||||
],
|
||||
"consumes": [
|
||||
"container-image-registry.published",
|
||||
"container-image-registry.refused",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
"container-image-registry.refused"
|
||||
],
|
||||
"own-secrets": {
|
||||
"broker": "${dir:state}/broker"
|
||||
|
||||
@@ -41,22 +41,9 @@ func (m *Module) askSteps(steps []StepTool) steprun.AskSteps {
|
||||
},
|
||||
Release: func(ws string) error { return m.spaces().Release(ws) },
|
||||
Logf: m.Say,
|
||||
Has: m.Has,
|
||||
Lint: m.lintStep,
|
||||
Node: m.Node,
|
||||
SayStep: m.sayStep(),
|
||||
}
|
||||
}
|
||||
|
||||
// sayStep says a pipeline step's end on this node's subject of the seat (design 47 G §24, *Asked on a work queue, ended by an
|
||||
// event*): SayStep when a test sets it, else the runtime's seat publish.
|
||||
func (m *Module) sayStep() func(sdkstep.StepEnded) error {
|
||||
if m.SayStep != nil {
|
||||
return m.SayStep
|
||||
}
|
||||
return steprun.SayStepOn(sdkstep.AskNode, m.Node, stdio.SeatPublish)
|
||||
}
|
||||
|
||||
// Puller is the module's pull of its seat's asks, on source (the runtime's seat pull when nil).
|
||||
func (m *Module) Puller(steps []StepTool, source steprun.AskSource) *steprun.Puller {
|
||||
if source == nil {
|
||||
@@ -92,7 +79,7 @@ func (m *Module) Puller(steps []StepTool, source steprun.AskSource) *steprun.Pul
|
||||
if m.SayEvent != nil {
|
||||
say = steprun.SayOn(sdkstep.AskNode, m.Node, m.SayEvent)
|
||||
}
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskNode, Say: say, Callers: m.Callers, Prior: steprun.PriorRuns(m.ReadSteps.Get), Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
return &steprun.Puller{KeepOutput: steprun.KeepOutputIn(m.Outputs), Source: source, Language: sdkstep.AskNode, Say: say, Callers: m.Callers, Node: m.Node, Put: m.Steps, PausePut: m.Pauses, Load: load, ForgetPause: m.ForgetPause, WatchPauses: m.WatchPauses, PauseKeys: m.ReadPauses.Keys,
|
||||
Capacity: capacity, SettingsFile: settings, WatchConfig: watch, CoresPerStep: cores, BuildHours: hours, Logf: m.Say,
|
||||
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) {
|
||||
if err := m.Prepare(ctx); err != nil {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
||||
)
|
||||
@@ -227,54 +226,3 @@ func TestTheTestScriptFindsTscAndEsbuildOnItsPath(t *testing.T) {
|
||||
t.Errorf("npm ran with %v, want NODE_OPTIONS naming the TAP reporter and its file", npm.env)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §328 (*Lint per language*: TypeScript's lint is the type-check) and §24: the pipeline step lint of a TypeScript
|
||||
// artifact runs tsc without emitting over the module's directory; a type error fails it naming the file, a clean package passes,
|
||||
// a tree with no .ts file has nothing to lint, and a tsc that cannot start is an error, not a verdict.
|
||||
func TestTheLintStepIsTheTypeCheck(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
files map[string]string
|
||||
ran forgekey.Ran
|
||||
failed int
|
||||
nothing bool
|
||||
err bool
|
||||
}{
|
||||
{"a type error", map[string]string{"tools/bad.ts": `export const n: number = "text";`}, forgekey.Ran{Status: 2, Stdout: tscTypeError}, 1, false, false},
|
||||
{"a clean package", map[string]string{"index.ts": `export const a = 1;`}, forgekey.Ran{}, 0, false, false},
|
||||
{"no TypeScript", map[string]string{"package.json": `{"name":"x"}`}, forgekey.Ran{}, 0, true, false},
|
||||
{"tsc cannot start", map[string]string{"index.ts": `export const a = 1;`}, forgekey.Ran{Status: 127, Err: "no such file"}, 0, false, true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m, f, work := newMachine(t)
|
||||
workspaceWith(t, work, c.files)
|
||||
f.answer["tsc"] = c.ran
|
||||
out, err := m.lintStep(context.Background(), map[string]any{"workspace": "w1", "dir": "."})
|
||||
if (err != nil) != c.err {
|
||||
t.Fatalf("error = %v, want error %v", err, c.err)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
la := out.(steprun.LintAnswer)
|
||||
if len(la.Failed) != c.failed || la.Nothing != c.nothing {
|
||||
t.Fatalf("answer = %+v, want %d failed, nothing %v", la, c.failed, c.nothing)
|
||||
}
|
||||
if c.failed > 0 && !strings.Contains(la.Failed[0].Cause+la.Failed[0].Output, "tools/bad.ts") {
|
||||
t.Errorf("the failure %+v does not name tools/bad.ts", la.Failed[0])
|
||||
}
|
||||
if !c.nothing && !strings.Contains(joined(f.calls[0]), "--noEmit") {
|
||||
t.Errorf("the lint ran %s, want tsc --noEmit", joined(f.calls[0]))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §24: the Node build module's steps carry what a step ask needs (its node, the lint body, the end's publisher and
|
||||
// its own need), so the ask the first live pipeline sent is no longer refused as "says no step's end".
|
||||
func TestTheNodeStepsCarryWhatAStepAskNeeds(t *testing.T) {
|
||||
s := (&Module{Node: "shanks"}).askSteps(nil)
|
||||
if s.Lint == nil || s.Node != "shanks" || s.SayStep == nil || s.Has == nil || !s.Has(sdkstep.NeedNodeBuildNode) || s.Has("other") {
|
||||
t.Errorf("steps = %+v, want Lint, Node, SayStep and Has set", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -50,19 +49,3 @@ func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A-489b, design 47 G §24: the module's own steps can say a pipeline step's end, or
|
||||
// every step ask the runner sends it is refused ("this build module says no step's end"), as the first live pipeline met.
|
||||
func TestTheStepsCanSayAStepsEnd(t *testing.T) {
|
||||
conformance.StepEnds(t, (&Module{Node: "kitnode"}).askSteps(nil))
|
||||
}
|
||||
|
||||
// A-489c (A-489a): the module's puller counts the runs its steps state says started, not the bus's deliveries (an ask given back before
|
||||
// it ran is no run), so the poison rule never ends an ask that never ran.
|
||||
func TestThePullerCountsRunsThatStarted(t *testing.T) {
|
||||
conformance.RunsCounted(t, func(read func(string) (json.RawMessage, error)) *steprun.Puller {
|
||||
m := &Module{Node: "kitnode", Capacity: func() int { return 1 }}
|
||||
m.ReadSteps = StateRead{Get: read}
|
||||
return m.Puller(nil, steprun.NewFakeAsks())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
)
|
||||
|
||||
// **The type-check is a TypeScript artifact's pipeline step lint** (design 47 G §328 *Lint per language*: Go's lint is the Go
|
||||
// build module's linter, TypeScript's the type-check; §22: lint is a step the build seats serve; §24: asked on a work queue,
|
||||
// its end said as an event). It takes {"workspace", "dir"} as the lint step of mesh-build-go does and runs tsc over each
|
||||
// TypeScript package of the module's directory (testTargets, the way the unit level finds them), without emitting: a package
|
||||
// with no .ts file has nothing to lint, and nothing at all ends the step `nothing to run`. A failure is the step's, naming
|
||||
// the tsc output as the unit level names it; a tsc that could not start is an error, never a verdict.
|
||||
func (m *Module) lintStep(ctx context.Context, args map[string]any) (any, error) {
|
||||
workspace, _ := args["workspace"].(string)
|
||||
dir, _ := args["dir"].(string)
|
||||
root, mdir, err := m.moduleDirOf(workspace, dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
targets, err := testTargets(mdir, filepath.ToSlash(filepath.Clean(dir)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var failed []Failure
|
||||
linted := false
|
||||
for _, tg := range targets {
|
||||
sources, err := typeScriptFiles(tg.dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
continue
|
||||
}
|
||||
linted = true
|
||||
if err := m.provide(root); err != nil {
|
||||
return nil, fmt.Errorf("providing the toolchain's packages to the workspace: %w", err)
|
||||
}
|
||||
r := m.runIn(ctx, root, false, tg.dir, nil, "node", m.typeCheck(tg.dir, sources)...)
|
||||
if r.Err != "" {
|
||||
return nil, fmt.Errorf("type-check could not be run: status %d %s: %s", r.Status, r.Err, firstLine(r.Stderr))
|
||||
}
|
||||
if r.Status != 0 {
|
||||
failed = append(failed, testFailures(tg.where, "type-check", tg.dir, r, "")...)
|
||||
}
|
||||
}
|
||||
return steprun.LintAnswer{Failed: failed, Nothing: !linted}, nil
|
||||
}
|
||||
|
||||
// A-489b: Has says whether this node has a need a package's tests name (sdkstep.AskNeeds): the need node-build-node is this module's own
|
||||
// (a TypeScript package's tests run through it); any other it lacks.
|
||||
func (m *Module) Has(need string) bool { return need == sdkstep.NeedNodeBuildNode }
|
||||
@@ -277,17 +277,6 @@ func TestTheModuleRequiresNodeToolsItPullsThrough(t *testing.T) {
|
||||
if !slices.Contains(m.Requires, "node-tools") {
|
||||
t.Errorf("requires %v lack node-tools", m.Requires)
|
||||
}
|
||||
// Design 47 G A-488a: its runtime follows the seat list (seatlist.Start subscribes to the seat mesh-catalog's events), so the
|
||||
// module consumes both, which makes its durable consumer <node>_mesh-build-node_tools: with none, the seat list is never
|
||||
// read and the asks of a named asker are given back for ever.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions (A-488b)", m.Invokes)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-254, A-313, A-314: the module keeps a run's answer over what step-ended carries inline in the steps state's own
|
||||
|
||||
@@ -34,9 +34,6 @@ type Module struct {
|
||||
// puller's ask-taken, step-progress and step-ended (design 47 G §496, §602).
|
||||
SayEvent func(subject string, body any, id string) error
|
||||
|
||||
// SayStep says a pipeline step's end (steprun.AskSteps.SayStep); the seat's publish on this node when nil (a test's own).
|
||||
SayStep func(sdkstep.StepEnded) error
|
||||
|
||||
Node string
|
||||
// Recipe is the recipe in force. Reload, when set, reads it again at every check (the lock file the mesh
|
||||
// writes can change under a running module); a failure to read it is a refusal.
|
||||
|
||||
@@ -24,10 +24,6 @@
|
||||
"serves": ["current", "drop", "pause", "resume", "steps", "kept-artifact", "output"]
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
],
|
||||
"config": {
|
||||
"capacity": {
|
||||
"type": "number",
|
||||
@@ -80,8 +76,7 @@
|
||||
"seat:npm-package-registry.publish",
|
||||
"seat:npm-package-registry.publish-part",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions"
|
||||
"seat:mesh-catalog.module"
|
||||
],
|
||||
"own-secrets": {
|
||||
"broker": "${dir:state}/broker"
|
||||
|
||||
@@ -19,6 +19,7 @@ itself (NetworkManager's VPNs, WireGuard set up by networkd, Tailscale) needs no
|
||||
| `/etc/node-resolver/resolv.conf` | the same file, kept beside it for the guard to compare with and put back |
|
||||
| `/etc/node-resolver/suffix` | the mesh's own domain, which a route may never take |
|
||||
| `/etc/systemd/resolved.conf.d/50-mesh.conf` | every mesh resolver as the default route for names (`DNS=`, `Domains=~.`), no public fallback, the stub on loopback and on the private address, no cache, no LLMNR or mDNS |
|
||||
| `/etc/node-resolver/answer-within` | the config value `answer-within`: how long the guard gives each of the mesh's resolvers to answer before it takes them for silent (issue 1981) |
|
||||
|
||||
**On the private address, so containers reach it.** A container copies its machine's resolver file and
|
||||
cannot reach the machine's loopback, so the file names the address the machine has on the private
|
||||
@@ -49,6 +50,15 @@ One long-running process, as root: `resolver-tools guard`.
|
||||
still raised, naming the writer, for a write nothing on the machine declared to handle.
|
||||
- **Only the mesh's resolvers answer every name.** Every five seconds, a link that a network manager gave
|
||||
servers of its own is told it is not a default route for names. Its own domains stay its own.
|
||||
- **While the mesh's resolvers are silent, a network's own servers answer.** Behind a network's sign-in
|
||||
page (a guest or hotel network) the private network is out of reach until the person signs in, so no
|
||||
name, the page's included, would resolve. Every five seconds the guard first asks each of the mesh's
|
||||
resolvers a name under the mesh's domain, straight over the network, each within the config value
|
||||
`answer-within` (seconds, default 1); while none answers, every link a network manager gave servers is a
|
||||
default route again, read from resolved each round (so it holds after the guard restarts), and a network
|
||||
joined meanwhile keeps its default route. A link `route` routed (a VPN's) never is. Once one answers,
|
||||
they lose it within five seconds. The guard says both turns on
|
||||
its journal, and the node's network check still says the mesh's names do not resolve.
|
||||
- **What it says elsewhere** — the `routes` verb's `outside_writes`, from `/run/node-resolver/history.json`
|
||||
— is when, the writer's name and what became of each write. It never includes a server or a domain.
|
||||
|
||||
|
||||
@@ -90,6 +90,10 @@ type Guard struct {
|
||||
pending *Displacement
|
||||
history []Displacement
|
||||
wake chan struct{}
|
||||
|
||||
// silent is whether none of the mesh's resolvers answered at the last look, so each turn is said once.
|
||||
// Only the routes' loop reads and writes it.
|
||||
silent bool
|
||||
}
|
||||
|
||||
// NewGuard is the machine's.
|
||||
@@ -330,13 +334,39 @@ func (g *Guard) Run(ctx context.Context) {
|
||||
case <-g.wake:
|
||||
g.Tick()
|
||||
case <-routes.C:
|
||||
if changed, err := g.Resolver.OnlyTheMeshIsADefaultRoute(ctx); err == nil && len(changed) > 0 {
|
||||
g.Log("%s had servers answering every name; now only their own domains", strings.Join(changed, ", "))
|
||||
}
|
||||
g.KeepRoutes(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KeepRoutes keeps every link's own servers from being a default route while one of the mesh's resolvers
|
||||
// answers. While none does, as behind a network's sign-in page, the links it kept from it answer every name
|
||||
// again, so the page can be found; once one answers, they are kept from it once more. Which links is read
|
||||
// from resolved each round; the guard keeps no list of its own.
|
||||
func (g *Guard) KeepRoutes(ctx context.Context) {
|
||||
routes, err := g.Resolver.Routes(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !g.Resolver.TheMeshAnswers(ctx, routes.Mesh.Servers) {
|
||||
if !g.silent {
|
||||
g.silent = true
|
||||
g.Log("none of the mesh's resolvers answers; a network's own servers answer every name until one does")
|
||||
}
|
||||
if changed, err := g.Resolver.ADefaultRouteAgain(ctx, routes); err == nil && len(changed) > 0 {
|
||||
g.Log("%s answers every name again, while the mesh's resolvers are silent", strings.Join(changed, ", "))
|
||||
}
|
||||
return
|
||||
}
|
||||
if g.silent {
|
||||
g.silent = false
|
||||
g.Log("one of the mesh's resolvers answers again")
|
||||
}
|
||||
if changed, err := g.Resolver.OnlyTheMeshIsADefaultRoute(ctx); err == nil && len(changed) > 0 {
|
||||
g.Log("%s had servers answering every name; now only their own domains", strings.Join(changed, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
// Request is one call over the socket: a verb and its arguments, one JSON line.
|
||||
type Request struct {
|
||||
Verb string `json:"verb"`
|
||||
|
||||
@@ -249,3 +249,59 @@ func TestTheVerbsOnTheMachine(t *testing.T) {
|
||||
t.Errorf("the mesh's domain over the socket: %+v", r)
|
||||
}
|
||||
}
|
||||
|
||||
// Behind a network's sign-in page the mesh's resolvers are out of reach, so a link a network manager gave
|
||||
// servers answers every name again until one of the mesh's resolvers answers; then it is kept from it once
|
||||
// more. A link `route` routed keeps its default route off, even one the guard turned off before it was
|
||||
// routed, and a guard started afresh behind the page finds the link from resolved alone. (1981/AC1)
|
||||
func TestTheNetworksServersAnswerWhileTheMeshsResolversAreSilent(t *testing.T) {
|
||||
g, _, f := aGuardedMachine(t)
|
||||
meshAnswers := true
|
||||
g.Resolver.Answers = func(_ context.Context, server string) bool { return meshAnswers && server == "10.42.0.1" }
|
||||
f.dns = "Global: 10.42.0.1 10.42.0.2\nLink 2 (wlan0): 192.168.1.1\nLink 7 (tun0): 10.9.0.1\n"
|
||||
ctx := context.Background()
|
||||
step := func(g *Guard, domains, defaults string, want ...string) {
|
||||
t.Helper()
|
||||
f.domain, f.defaults, f.changed = domains, defaults, nil
|
||||
g.KeepRoutes(ctx)
|
||||
var got []string
|
||||
for _, c := range f.changed {
|
||||
got = append(got, strings.Join(c, " "))
|
||||
}
|
||||
if strings.Join(got, "; ") != strings.Join(want, "; ") {
|
||||
t.Errorf("changed %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
// tun0 comes up with servers and a default route, is turned off, and is then routed.
|
||||
step(g, "Global: ~.\nLink 2 (wlan0): lan\nLink 7 (tun0):\n", "Link 2 (wlan0): yes\nLink 7 (tun0): yes\n",
|
||||
"resolvectl default-route tun0 false", "resolvectl default-route wlan0 false")
|
||||
routed := "Global: ~.\nLink 2 (wlan0): lan\nLink 7 (tun0): ~corp.example\n"
|
||||
meshAnswers = false
|
||||
step(g, routed, "Link 2 (wlan0): no\nLink 7 (tun0): no\n", "resolvectl default-route wlan0 true")
|
||||
step(g, routed, "Link 2 (wlan0): yes\nLink 7 (tun0): no\n")
|
||||
afresh, _, _ := aGuardedMachine(t)
|
||||
afresh.Resolver = g.Resolver
|
||||
step(afresh, routed, "Link 2 (wlan0): no\nLink 7 (tun0): no\n", "resolvectl default-route wlan0 true")
|
||||
meshAnswers = true
|
||||
step(g, routed, "Link 2 (wlan0): yes\nLink 7 (tun0): no\n", "resolvectl default-route wlan0 false")
|
||||
}
|
||||
|
||||
// A network joined while the mesh's resolvers are silent keeps its default route, and loses it once one answers.
|
||||
// (1981/AC2)
|
||||
func TestANetworkJoinedWhileTheMeshIsSilentKeepsItsDefaultRoute(t *testing.T) {
|
||||
g, _, f := aGuardedMachine(t)
|
||||
meshAnswers := false
|
||||
g.Resolver.Answers = func(context.Context, string) bool { return meshAnswers }
|
||||
f.dns = "Global: 10.42.0.1\nLink 2 (wlan0): 192.168.1.1\n"
|
||||
f.domain = "Global: ~.\n"
|
||||
f.defaults = "Link 2 (wlan0): yes\n"
|
||||
g.KeepRoutes(context.Background())
|
||||
if len(f.changed) != 0 {
|
||||
t.Errorf("changed %v while the mesh was silent", f.changed)
|
||||
}
|
||||
meshAnswers = true
|
||||
g.KeepRoutes(context.Background())
|
||||
if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl default-route wlan0 false" {
|
||||
t.Errorf("changed %v once the mesh answered", f.changed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -85,11 +87,58 @@ type Resolver struct {
|
||||
NetDir string
|
||||
// SuffixFile holds the mesh's own domain, which is never routed elsewhere.
|
||||
SuffixFile string
|
||||
// Answers says whether one of the mesh's resolvers answers a name now.
|
||||
Answers func(ctx context.Context, server string) bool
|
||||
// AnswerWithinFile holds how long one of them is given to answer (the config value answer-within).
|
||||
AnswerWithinFile string
|
||||
}
|
||||
|
||||
// ThisResolver is the machine's.
|
||||
func ThisResolver() *Resolver {
|
||||
return &Resolver{Change: execRunner, Read: readRunner, NetDir: "/sys/class/net", SuffixFile: SuffixPath}
|
||||
r := &Resolver{Change: execRunner, Read: readRunner, NetDir: "/sys/class/net", SuffixFile: SuffixPath,
|
||||
AnswerWithinFile: AnswerWithinPath}
|
||||
r.Answers = r.asks
|
||||
return r
|
||||
}
|
||||
|
||||
// AnswerWithinPath is the file the mesh renders the config value answer-within into, as `seconds=<n>`.
|
||||
const AnswerWithinPath = "/etc/node-resolver/answer-within"
|
||||
|
||||
// DefaultAnswerWithin is the config value's default, used until the mesh has rendered the file.
|
||||
const DefaultAnswerWithin = time.Second
|
||||
|
||||
// answerWithin is how long one of the mesh's resolvers is given to answer the guard's question, read each
|
||||
// round, so a changed config value holds from the next round on.
|
||||
func (r *Resolver) answerWithin() time.Duration {
|
||||
raw, err := os.ReadFile(r.AnswerWithinFile)
|
||||
if err != nil {
|
||||
return DefaultAnswerWithin
|
||||
}
|
||||
for _, line := range strings.Split(string(raw), "\n") {
|
||||
if v, ok := strings.CutPrefix(strings.TrimSpace(line), "seconds="); ok {
|
||||
if n, err := strconv.ParseFloat(v, 64); err == nil && n > 0 {
|
||||
return time.Duration(n * float64(time.Second))
|
||||
}
|
||||
}
|
||||
}
|
||||
return DefaultAnswerWithin
|
||||
}
|
||||
|
||||
// asks one of the mesh's resolvers a name under the mesh's own domain, straight over the network and not
|
||||
// through resolved: any answer, a name not found included, is an answer; only silence is not.
|
||||
func (r *Resolver) asks(ctx context.Context, server string) bool {
|
||||
ctx, cancel := context.WithTimeout(ctx, r.answerWithin())
|
||||
defer cancel()
|
||||
ask := &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
|
||||
var d net.Dialer
|
||||
if _, _, err := net.SplitHostPort(server); err == nil {
|
||||
return d.DialContext(ctx, network, server)
|
||||
}
|
||||
return d.DialContext(ctx, network, net.JoinHostPort(server, "53"))
|
||||
}}
|
||||
_, err := ask.LookupHost(ctx, "node-resolver-asks."+r.suffix())
|
||||
var dnsErr *net.DNSError
|
||||
return err == nil || (errors.As(err, &dnsErr) && dnsErr.IsNotFound)
|
||||
}
|
||||
|
||||
// SuffixPath is the file the mesh renders the mesh's own domain into (the manifest's fact `suffix`).
|
||||
@@ -103,6 +152,9 @@ type Scope struct {
|
||||
Domains []string `json:"domains"`
|
||||
// DefaultRoute is whether names no domain routes may also go here. Only the mesh's resolvers are.
|
||||
DefaultRoute *bool `json:"default_route,omitempty"`
|
||||
|
||||
// routed is a link given its domains by `route`: every one a routing domain, as Route writes them.
|
||||
routed bool
|
||||
}
|
||||
|
||||
// Routes is what resolved sends where.
|
||||
@@ -132,6 +184,17 @@ func perScope(out string) (global []string, links map[string][]string) {
|
||||
return global, links
|
||||
}
|
||||
|
||||
// onlyRouting is whether a link's domains are all routing domains, as `route` gives them; a network manager
|
||||
// gives a network's search domains, without the `~`.
|
||||
func onlyRouting(domains []string) bool {
|
||||
for _, d := range domains {
|
||||
if !strings.HasPrefix(d, "~") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(domains) > 0
|
||||
}
|
||||
|
||||
func unrouted(domains []string) []string {
|
||||
out := make([]string, 0, len(domains))
|
||||
for _, d := range domains {
|
||||
@@ -163,7 +226,7 @@ func (r *Resolver) Routes(ctx context.Context) (*Routes, error) {
|
||||
}
|
||||
sort.Strings(names)
|
||||
for _, name := range names {
|
||||
s := Scope{Link: name, Servers: lServers[name], Domains: orEmpty(unrouted(lDomains[name]))}
|
||||
s := Scope{Link: name, Servers: lServers[name], Domains: orEmpty(unrouted(lDomains[name])), routed: onlyRouting(lDomains[name])}
|
||||
if d, ok := lDefault[name]; ok && len(d) > 0 {
|
||||
yes := d[0] == "yes"
|
||||
s.DefaultRoute = &yes
|
||||
@@ -376,3 +439,37 @@ func (r *Resolver) OnlyTheMeshIsADefaultRoute(ctx context.Context) ([]string, er
|
||||
}
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
// TheMeshAnswers says whether one of the mesh's resolvers answers now, asking them all at once. Behind a
|
||||
// network's sign-in page none does: the private network is out of reach until the person signs in.
|
||||
func (r *Resolver) TheMeshAnswers(ctx context.Context, servers []string) bool {
|
||||
answered := make(chan bool, len(servers))
|
||||
for _, s := range servers {
|
||||
go func() { answered <- r.Answers(ctx, s) }()
|
||||
}
|
||||
for range servers {
|
||||
if <-answered {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ADefaultRouteAgain lets every link a network manager gave servers answer every name again, while the
|
||||
// mesh's resolvers are silent: a network's own servers are then the only ones that can find its sign-in
|
||||
// page. Read from what resolved holds, not from what the guard did, so it holds after the guard restarts.
|
||||
// A link `route` routed (a VPN's) is never one, and one that already answers every name is left alone.
|
||||
// Answers the links it changed.
|
||||
func (r *Resolver) ADefaultRouteAgain(ctx context.Context, routes *Routes) ([]string, error) {
|
||||
var changed []string
|
||||
for _, l := range routes.Links {
|
||||
if l.routed || l.DefaultRoute == nil || *l.DefaultRoute {
|
||||
continue
|
||||
}
|
||||
if _, err := r.Change(ctx, "resolvectl", "default-route", l.Link, "true"); err != nil {
|
||||
return changed, err
|
||||
}
|
||||
changed = append(changed, l.Link)
|
||||
}
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fakeResolved answers resolvectl as systemd-resolved would, and records what was asked of it.
|
||||
@@ -170,3 +172,52 @@ func TestChangesAreEscalatedOnlyWhenNotRoot(t *testing.T) {
|
||||
t.Errorf("as the account: %s %v", p, a)
|
||||
}
|
||||
}
|
||||
|
||||
// One of the mesh's resolvers answers when it says anything, a name not found included; one that is silent
|
||||
// does not, and the guard does not wait on it past the config value answer-within, read from the file the
|
||||
// mesh renders, or a second before it has. (1981/AC3)
|
||||
func TestAResolverAnswersUnlessItIsSilent(t *testing.T) {
|
||||
conn, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
go func() {
|
||||
buf := make([]byte, 512)
|
||||
for {
|
||||
n, from, err := conn.ReadFrom(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
reply := append([]byte{}, buf[:n]...)
|
||||
reply[2], reply[3] = 0x81, 0x83 // a reply, recursion available, the name not found
|
||||
conn.WriteTo(reply, from)
|
||||
}
|
||||
}()
|
||||
silent, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer silent.Close()
|
||||
r := aMachine(t, &fakeResolved{})
|
||||
r.AnswerWithinFile = filepath.Join(t.TempDir(), "answer-within")
|
||||
if got := r.answerWithin(); got != DefaultAnswerWithin {
|
||||
t.Errorf("before the file is rendered, a resolver is given %v", got)
|
||||
}
|
||||
if err := os.WriteFile(r.AnswerWithinFile, []byte("# written by the mesh\nseconds=0.1\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := r.answerWithin(); got != 100*time.Millisecond {
|
||||
t.Errorf("with answer-within 0.1, a resolver is given %v", got)
|
||||
}
|
||||
if !r.asks(context.Background(), conn.LocalAddr().String()) {
|
||||
t.Error("a resolver that said the name is not found did not answer")
|
||||
}
|
||||
start := time.Now()
|
||||
if r.asks(context.Background(), silent.LocalAddr().String()) {
|
||||
t.Error("a silent resolver answered")
|
||||
}
|
||||
if took := time.Since(start); took > 300*time.Millisecond {
|
||||
t.Errorf("a silent resolver was waited on %v", took)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# How long, in seconds, the guard gives one of the mesh's resolvers to answer, from the config value
|
||||
# answer-within, written by the mesh (module systemd-resolved, novox/hq issue 1981). Replaced on every
|
||||
# push; change the config value, never this file.
|
||||
seconds=${config:answer-within}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"module": "systemd-resolved",
|
||||
"version": "0.1",
|
||||
"version": "0.2",
|
||||
"upgrade": {
|
||||
"policy": "record",
|
||||
"why": "the machine's names: a build that breaks this resolver stops every name resolving on a machine a person works on, the bus's included, and then neither the gate's rollback nor a push reaches it (hq ADR 0236, ADR 0247)"
|
||||
@@ -81,6 +81,14 @@
|
||||
"kind": "unit"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "answer-within",
|
||||
"type": "file",
|
||||
"path": "/etc/node-resolver/answer-within",
|
||||
"mode": "0644",
|
||||
"trusted": false,
|
||||
"template": "files/answer-within"
|
||||
},
|
||||
{
|
||||
"id": "guard",
|
||||
"type": "process",
|
||||
@@ -109,5 +117,14 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"answer-within": {
|
||||
"type": "number",
|
||||
"description": "How long, in seconds, the guard gives one of the mesh's resolvers to answer its question each round (novox/hq issue 1981): while none answers within it, a network's own servers answer every name, so a sign-in page can be found. 1 suits a tunnel's usual round trip; a slower link (tethered, abroad) needs more, or the guard takes a slow mesh for a silent one.",
|
||||
"minimum": 0.2,
|
||||
"maximum": 5,
|
||||
"default": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user