headless: checks-end progress line and a run id on every line
Astra p34-r2 finding 4. A hosted scenario appends HOSTED-CHECKS-END the moment it sees its checks step end, before it fetches the task or reads the database copy, so the drill settles the step's VMs without waiting. ended_at is the step's finished_at from the person API, capped at when the scenario saw it; without one, the last time the step was seen live: never later than the real end. staging-thin.py makes the run id first and gives it to fresh_suite; every progress line, the suite's and the scenarios', carries run=<id>.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+206
−39
.rastrillo/budgets.txt+1 −1docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+36 −0internal/headless/hosted_fixture_test.go+55 −4internal/headless/hosted_test.go+88 −25scripts/staging-thin-test.py+13 −3scripts/staging-thin.py+13 −6
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index a948d15d..edc738af 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -75,7 +75,7 @@ perf GET /api/v1/tasks/{id}/files/{file} skip Research kept images: bearer-only |
| perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one image, shown on the task page; a file, not a screen. |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| -size internal/headless - 14536 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files; restart wait; live site waits; card answer; scenario 7; Mac M9, mixed versions; 13400. Hosted slice 2: the dev drill's four hosted checks scenarios, their scratch project and its offline checks; drill modes, the checks-started barrier and bounded ends; 14536. |
| +size internal/headless - 14650 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files; restart wait; live site waits; card answer; scenario 7; Mac M9, mixed versions; 13400. Hosted slice 2: the dev drill's four hosted checks scenarios, their scratch project and its offline checks; drill modes, the checks-started barrier and bounded ends; the checks-end line and run ids; 14650. |
| size internal/thintest - 42664 Protocol 31 to 38 contracts, Design end to end; hosted slice 2 Task 26: protocol 39 and 40 rows, older primaries' Research ends runner_update_needed; 42664. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index 56009705..d1e26070 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -3760,3 +3760,39 @@ caught four span defects on the way (a `--teardown` block without its command, a |
| `--max`, a `--step` given a shell variable, `img delete -ledger` without a value); each was fixed in |
| the plan text. The `run.env` helpers were run against a fake `ops`: `upoll` gave `done`, `over` and |
| `unreadable`; `ordinary 99` and `img_ordinary 4` exited 99; the barrier and suite lines parsed. |
| + |
| +## Headless hosted scenarios: checks-end line and run ids (Astra p34-r2 finding 4, 2026-12-02) |
| + |
| +**The checks-end line.** When a hosted scenario sees its checks step end, it appends `HOSTED-CHECKS-END` |
| +to the progress file at once (`endChecks`). Only then does it fetch the task, cancel it, and read the |
| +database copy, which can take up to 5 minutes. |
| + |
| +**`ended_at`.** It is the step's `finished_at` from the person API (the instance's own end time), |
| +capped at the moment the scenario saw the end. Without a `finished_at`, it is the last time the step |
| +was seen not ended, which is never later than the real end. |
| + |
| +**Run ids.** `staging-thin.py suite` makes the run id before anything else (`new_run_id`) and gives |
| +it to `fresh_suite`. The id is `EQUIPO_STAGING_RUN_ID` and the suite person's. Every progress line |
| +carries `run=<id>`: `HOSTED-SUITE-START`, `-START`, `-TASK`, `-BARRIER`, `-CHECKS-END`, `-END` and |
| +`HOSTED-SUITE`. A refused mode gets an id too. |
| + |
| +**Red first.** `TestHostedBarrierLine` (`run=`), `TestHostedChecksEndLine` and |
| +`TestHostedChecksEndBeforeEvidence` FAILED on their assertions against stubs. |
| +`test_fresh_runs_and_green_record` FAILED on `HOSTED-SUITE-START scenarios=all mode=plain` against |
| +`... run=<id> ...`. All four then went green. |
| + |
| +Green: `go test ./internal/headless -run '^(TestHosted.*|TestStaging)$'`, |
| +`-run '^TestHeadless$/^hosted'` (four skips), `go vet`, `scripts/staging-thin-test.py` (17). The |
| +`internal/headless` record is raised to 14650. `make budget`'s other problem, `internal/hostedops` |
| +at 7658, is another agent's work in progress. |
| + |
| +Mutation checks, each restored: |
| +- **H11** `endChecks` collecting before it writes: `TestHostedChecksEndBeforeEvidence` FAILED |
| + `collecting evidence before the step's end was written: ""`. |
| +- **H12** `ended_at` not capped at the observation: `TestHostedChecksEndLine` FAILED, |
| + `ended_at=...10:09:00Z` against `10:05:40Z`. |
| +- **H13** without `finished_at`, the observed time instead of the last time the step was seen live: |
| + `TestHostedChecksEndLine` FAILED, `ended_at=...10:05:40Z` against `10:04:50Z`. H12 and H13 ran in |
| + one run with H11, each failing its own case. |
| +- **H14** `fresh_suite` making its own run id: `test_fresh_runs_and_green_record` FAILED, the |
| + `HOSTED-SUITE-START` run differing from `EQUIPO_STAGING_RUN_ID`. |
diff --git a/internal/headless/hosted_fixture_test.go b/internal/headless/hosted_fixture_test.go| index 293c8511..b37cfc69 100644 |
| --- a/internal/headless/hosted_fixture_test.go |
| +++ b/internal/headless/hosted_fixture_test.go |
| @@ -16,6 +16,7 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner/depsbundle" |
| "amadan.net/oficina/equipo/internal/testci" |
| "amadan.net/oficina/equipo/internal/thintest" |
| + "amadan.net/oficina/equipo/internal/wire" |
| ) |
| // The hosted scenarios offline: their names and selection, when they run, |
| @@ -148,13 +149,63 @@ func TestHostedStatus(t *testing.T) { |
| func TestHostedBarrierLine(t *testing.T) { |
| b := newBarrier(time.Date(2026, 12, 2, 10, 0, 0, 0, time.UTC), "s1", "r1") |
| - if got, want := b.Line("hosted-slow", "stop-vm", "tk1"), "HOSTED-BARRIER name=hosted-slow mode=stop-vm task=tk1 step=s1 runner=r1 attempt=unknown vm=unknown launch=unknown at=2026-12-02T10:00:00Z strike_after=2026-12-02T10:00:30Z strike_before=2026-12-02T10:03:20Z"; got != want { |
| + if got, want := b.Line("run-1", "hosted-slow", "stop-vm", "tk1"), "HOSTED-BARRIER run=run-1 name=hosted-slow mode=stop-vm task=tk1 step=s1 runner=r1 attempt=unknown vm=unknown launch=unknown at=2026-12-02T10:00:00Z strike_after=2026-12-02T10:00:30Z strike_before=2026-12-02T10:03:20Z"; got != want { |
| t.Fatalf("\n got %s\nwant %s", got, want) |
| } |
| b.Attempt, b.VM, b.Launch = "hj-1", "vm-1", "l-1" |
| - if got := b.Line("hosted-slow", "stop-vm", "tk1"); !strings.Contains(got, " attempt=hj-1 vm=vm-1 launch=l-1 ") { |
| + if got := b.Line("run-1", "hosted-slow", "stop-vm", "tk1"); !strings.Contains(got, " attempt=hj-1 vm=vm-1 launch=l-1 ") { |
| t.Fatalf("ids: %s", got) |
| } |
| + if got, want := hostedEndLine("run-1", "hosted-slow", "stop-vm", "tk1", "ok", "yes", "state=done checks=passed"), "HOSTED-END run=run-1 name=hosted-slow mode=stop-vm task=tk1 status=ok matched=yes result=state=done checks=passed"; got != want { |
| + t.Fatalf("\n got %s\nwant %s", got, want) |
| + } |
| +} |
| + |
| +// TestHostedChecksEndLine: the step's end as the drill settles from it, |
| +// never later than the real end: the instance's own finished_at, capped |
| +// at when the scenario saw it; without one, the last time the step was |
| +// seen live. |
| +func TestHostedChecksEndLine(t *testing.T) { |
| + at := func(m, s int) time.Time { return time.Date(2026, 12, 2, 10, m, s, 0, time.UTC) } |
| + finished, late := at(5, 0), at(9, 0) |
| + b := newBarrier(at(0, 0), "s1", "r1") |
| + b.Attempt, b.VM = "hj-1", "mvm-1" |
| + for _, c := range []struct { |
| + st wire.Step |
| + b *hostedBarrier |
| + want string |
| + }{ |
| + {wire.Step{ID: "s1", State: "done", FinishedAt: &finished}, &b, |
| + "HOSTED-CHECKS-END run=run-1 name=hosted-slow mode=stop-vm task=tk1 step=s1 attempt=hj-1 vm=mvm-1 ended_at=2026-12-02T10:05:00Z at=2026-12-02T10:05:40Z"}, |
| + {wire.Step{ID: "s1", State: "done"}, nil, |
| + "HOSTED-CHECKS-END run=run-1 name=hosted-slow mode=stop-vm task=tk1 step=s1 attempt=unknown vm=unknown ended_at=2026-12-02T10:04:50Z at=2026-12-02T10:05:40Z"}, |
| + {wire.Step{ID: "s1", State: "done", FinishedAt: &late}, &b, |
| + "HOSTED-CHECKS-END run=run-1 name=hosted-slow mode=stop-vm task=tk1 step=s1 attempt=hj-1 vm=mvm-1 ended_at=2026-12-02T10:05:40Z at=2026-12-02T10:05:40Z"}, |
| + } { |
| + if got := checksEndLine("run-1", "hosted-slow", "stop-vm", "tk1", c.st, c.b, at(4, 50), at(5, 40)); got != c.want { |
| + t.Errorf("\n got %s\nwant %s", got, c.want) |
| + } |
| + } |
| +} |
| + |
| +// TestHostedChecksEndBeforeEvidence: the step's end is in the progress |
| +// file before any database evidence is collected. |
| +func TestHostedChecksEndBeforeEvidence(t *testing.T) { |
| + path := filepath.Join(t.TempDir(), "progress.log") |
| + t.Setenv("EQUIPO_STAGING_HOSTED_PROGRESS", path) |
| + const line = "HOSTED-CHECKS-END run=run-1 name=hosted-slow mode=plain task=tk1 step=s1 attempt=unknown vm=unknown ended_at=2026-12-02T10:05:00Z at=2026-12-02T10:05:01Z" |
| + collected := false |
| + o := endChecks(t, line, func() hostedOutcome { |
| + raw, _ := os.ReadFile(path) |
| + if lines := strings.Split(strings.TrimSpace(string(raw)), "\n"); lines[len(lines)-1] != line { |
| + t.Fatalf("collecting evidence before the step's end was written: %q", raw) |
| + } |
| + collected = true |
| + return hostedOutcome{Recorded: true, Jobs: 1} |
| + }) |
| + if !collected || !o.Recorded || o.Jobs != 1 { |
| + t.Fatalf("evidence %+v collected %v", o, collected) |
| + } |
| } |
| func TestHostedResultLine(t *testing.T) { |
| @@ -244,8 +295,8 @@ func TestHostedRecordQuery(t *testing.T) { |
| } else { |
| b.Attempt, b.VM, b.Launch = m[1], m[2], m[3] |
| } |
| - if !strings.Contains(b.Line("hosted-slow", "plain", "tk3"), " attempt=hj-live vm=mvm-0abc launch=l-9 ") { |
| - t.Fatal(b.Line("hosted-slow", "plain", "tk3")) |
| + if !strings.Contains(b.Line("run-1", "hosted-slow", "plain", "tk3"), " attempt=hj-live vm=mvm-0abc launch=l-9 ") { |
| + t.Fatal(b.Line("run-1", "hosted-slow", "plain", "tk3")) |
| } |
| } |
diff --git a/internal/headless/hosted_test.go b/internal/headless/hosted_test.go| index 2d868240..34ba1c8a 100644 |
| --- a/internal/headless/hosted_test.go |
| +++ b/internal/headless/hosted_test.go |
| @@ -517,15 +517,53 @@ func newBarrier(at time.Time, step, runner string) hostedBarrier { |
| } |
| // Line is the barrier as the progress file has it. |
| -func (b hostedBarrier) Line(name, mode, task string) string { |
| +func (b hostedBarrier) Line(run, name, mode, task string) string { |
| unknown := func(s string) string { |
| if s == "" { |
| return "unknown" |
| } |
| return s |
| } |
| - return fmt.Sprintf("HOSTED-BARRIER name=%s mode=%s task=%s step=%s runner=%s attempt=%s vm=%s launch=%s at=%s strike_after=%s strike_before=%s", |
| - name, mode, task, b.Step, b.Runner, unknown(b.Attempt), unknown(b.VM), unknown(b.Launch), stamp(b.At), stamp(b.StrikeAfter), stamp(b.StrikeBefore)) |
| + return fmt.Sprintf("HOSTED-BARRIER run=%s name=%s mode=%s task=%s step=%s runner=%s attempt=%s vm=%s launch=%s at=%s strike_after=%s strike_before=%s", |
| + run, name, mode, task, b.Step, b.Runner, unknown(b.Attempt), unknown(b.VM), unknown(b.Launch), stamp(b.At), stamp(b.StrikeAfter), stamp(b.StrikeBefore)) |
| +} |
| + |
| +// hostedEndLine is a scenario's last progress line. |
| +func hostedEndLine(run, name, mode, task, status, matched, result string) string { |
| + return fmt.Sprintf("HOSTED-END run=%s name=%s mode=%s task=%s status=%s matched=%s result=%s", run, name, mode, task, status, matched, result) |
| +} |
| + |
| +// checksEndLine is the progress line for the checks step's end, which the |
| +// drill settles the step's VMs from, so ended_at is never later than the |
| +// real end: the step's finished_at from the person API (the instance's |
| +// own end time), capped at now, when the scenario saw it; without one, |
| +// lastLive, the last time the step was seen not ended. attempt and vm are |
| +// the barrier's job (the step's first VM), unknown without one. |
| +func checksEndLine(run, name, mode, task string, st wire.Step, b *hostedBarrier, lastLive, now time.Time) string { |
| + ended := lastLive |
| + if st.FinishedAt != nil { |
| + ended = *st.FinishedAt |
| + if ended.After(now) { |
| + ended = now |
| + } |
| + } |
| + attempt, vm := "unknown", "unknown" |
| + if b != nil && b.Attempt != "" { |
| + attempt = b.Attempt |
| + } |
| + if b != nil && b.VM != "" { |
| + vm = b.VM |
| + } |
| + return fmt.Sprintf("HOSTED-CHECKS-END run=%s name=%s mode=%s task=%s step=%s attempt=%s vm=%s ended_at=%s at=%s", run, name, mode, task, st.ID, attempt, vm, stamp(ended), stamp(now)) |
| +} |
| + |
| +// endChecks writes the checks step's end to the progress file first, then |
| +// collects the evidence (the database copy, up to 5 minutes), so the |
| +// drill can settle the step's VMs without waiting for it. |
| +func endChecks(t *testing.T, line string, collect func() hostedOutcome) hostedOutcome { |
| + t.Helper() |
| + hostedProgress(t, "%s", line) |
| + return collect() |
| } |
| var hostedJobRow = regexp.MustCompile(`(?m)^job=([A-Za-z0-9_.:-]+) vm=(\S*) launch=(\S*) runner=(\S*)\s*$`) |
| @@ -610,6 +648,12 @@ func scenarioHosted(name string) func(*testing.T, *Env) { |
| return func(t *testing.T, env *Env) { |
| c, _ := hostedCaseNamed(name) |
| mode := hostedMode() |
| + // Every progress line names the suite run, so a run's lines are |
| + // never read as another's. |
| + run := env.RunID |
| + if run == "" { |
| + run = "-" |
| + } |
| repo, cookieFile := os.Getenv(hostedRepoEnv), os.Getenv("EQUIPO_STAGING_COOKIE_FILE") |
| skip, fail := hostedGate(env.Live, name, os.Getenv("EQUIPO_STAGING_SCENARIOS"), repo, cookieFile, mode) |
| if skip != "" { |
| @@ -619,9 +663,9 @@ func scenarioHosted(name string) func(*testing.T, *Env) { |
| // before the result is the suite's. |
| task, status, line, matched := "-", "suite_failed", "-", "no" |
| defer func() { |
| - hostedProgress(t, "HOSTED-END name=%s mode=%s task=%s status=%s matched=%s result=%s", name, mode, task, status, matched, line) |
| + hostedProgress(t, "%s", hostedEndLine(run, name, mode, task, status, matched, line)) |
| }() |
| - hostedProgress(t, "HOSTED-START name=%s mode=%s at=%s", name, mode, stamp(time.Now())) |
| + hostedProgress(t, "HOSTED-START run=%s name=%s mode=%s at=%s", run, name, mode, stamp(time.Now())) |
| if fail != "" { |
| t.Fatal(fail) |
| } |
| @@ -644,11 +688,14 @@ func scenarioHosted(name string) func(*testing.T, *Env) { |
| sent := s.send(t, fmt.Sprintf(c.ask, repo)) |
| id := s.taskOf(t, sent.Turn.ID) |
| task = id |
| - hostedProgress(t, "HOSTED-TASK name=%s mode=%s task=%s at=%s", name, mode, id, stamp(time.Now())) |
| + hostedProgress(t, "HOSTED-TASK run=%s name=%s mode=%s task=%s at=%s", run, name, mode, id, stamp(time.Now())) |
| hostedAt := -1.0 |
| var checks wire.Step |
| var runningAt time.Time |
| var runner string |
| + // lastLive is the last time the step was seen not ended (no later |
| + // than its real end), for an end the API gives no time for. |
| + lastLive := start |
| // Until the checks step runs on a VM (the barrier) or ends. |
| s.conv.Wait(hostedBarrierBound, func(c *thintest.Conversation) bool { |
| st, ok := firstChecks(c, id) |
| @@ -658,6 +705,9 @@ func scenarioHosted(name string) func(*testing.T, *Env) { |
| if st.Placement == wire.PlacementHosted && hostedAt < 0 { |
| hostedAt = time.Since(start).Seconds() |
| } |
| + if !wire.StepTerminal(st.State) { |
| + lastLive = time.Now() |
| + } |
| checks = st |
| if st.State == wire.StepRunning && st.RunnerID != "" && runningAt.IsZero() { |
| runningAt, runner = time.Now(), st.RunnerID |
| @@ -670,40 +720,53 @@ func scenarioHosted(name string) func(*testing.T, *Env) { |
| b := newBarrier(runningAt, checks.ID, runner) |
| hostedJobOf(t, &b) |
| barrier = &b |
| - hostedProgress(t, "%s", b.Line(name, mode, id)) |
| + hostedProgress(t, "%s", b.Line(run, name, mode, id)) |
| // Until it ends. A step still running then is recorded as it |
| // stands, then fails. |
| s.conv.Wait(time.Until(start.Add(hostedEndBound)), func(c *thintest.Conversation) bool { |
| st, ok := firstChecks(c, id) |
| if ok { |
| checks = st |
| + if !wire.StepTerminal(st.State) { |
| + lastLive = time.Now() |
| + } |
| } |
| return ok && wire.StepTerminal(st.State) || wire.FinalStage(c.Tasks[id].Stage) |
| }) |
| } |
| endedAt := time.Now() |
| - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) |
| - defer cancel() |
| - k, err := env.Client.Task(ctx, id) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - for _, st := range k.Steps { |
| - if st.ID == checks.ID { |
| - checks = st |
| + var k wire.Task |
| + collect := func() hostedOutcome { |
| + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) |
| + defer cancel() |
| + var err error |
| + if k, err = env.Client.Task(ctx, id); err != nil { |
| + t.Fatal(err) |
| } |
| - } |
| - // Nothing more runs on paid VMs: no fix round, no review. |
| - if !wire.FinalStage(k.Stage) { |
| - if _, err := env.Client.CancelTask(ctx, id); err != nil { |
| - t.Logf("cancelling %s: %v", id, err) |
| + for _, st := range k.Steps { |
| + if st.ID == checks.ID { |
| + checks = st |
| + } |
| + } |
| + // Nothing more runs on paid VMs: no fix round, no review. |
| + if !wire.FinalStage(k.Stage) { |
| + if _, err := env.Client.CancelTask(ctx, id); err != nil { |
| + t.Logf("cancelling %s: %v", id, err) |
| + } |
| } |
| + if checks.ID != "" && wire.StepTerminal(checks.State) { |
| + return hostedRecord(t, checks.ID, checks.State) |
| + } |
| + return hostedOutcome{} |
| } |
| - ended := checks.ID != "" && wire.StepTerminal(checks.State) |
| - o := hostedOutcome{} |
| - if ended { |
| - o = hostedRecord(t, checks.ID, checks.State) |
| + var o hostedOutcome |
| + if checks.ID != "" && wire.StepTerminal(checks.State) { |
| + // The step's end goes to the drill at once; the evidence after. |
| + o = endChecks(t, checksEndLine(run, name, mode, id, checks, barrier, lastLive, endedAt), collect) |
| + } else { |
| + o = collect() |
| } |
| + ended := checks.ID != "" && wire.StepTerminal(checks.State) |
| o.State, o.Checks, o.Reason, o.Shown, o.Sandbox, o.BaseSHA = checks.State, checks.Checks, checks.Reason, k.ChecksReason, checks.ChecksSandbox, checks.BaseSHA |
| line, status = o.Line(), hostedStatus(mode, checks.ID != "", ended, barrier, endedAt) |
| if expect.matched(o) { |
diff --git a/scripts/staging-thin-test.py b/scripts/staging-thin-test.py| index 3d22761b..4eb08f54 100644 |
| --- a/scripts/staging-thin-test.py |
| +++ b/scripts/staging-thin-test.py |
| @@ -2,6 +2,7 @@ import importlib.util |
| import json |
| import os |
| from pathlib import Path |
| +import re |
| import shlex |
| import tempfile |
| import sys |
| @@ -75,8 +76,10 @@ class SuiteTest(unittest.TestCase): |
| # started fresh for this run. |
| self.assertEqual(env['EQUIPO_STAGING_HOSTED_MODE'], modes[-1]) |
| self.assertEqual(env['EQUIPO_STAGING_HOSTED_PROGRESS'], str(root / 'hosted-progress.log')) |
| + # Its first line names this run, which the scenarios' |
| + # lines carry too (EQUIPO_STAGING_RUN_ID). |
| self.assertEqual(Path(env['EQUIPO_STAGING_HOSTED_PROGRESS']).read_text().splitlines()[0].split(' at=')[0], |
| - f'HOSTED-SUITE-START scenarios={env["EQUIPO_STAGING_SCENARIOS"] or "all"} mode={modes[-1]}') |
| + f'HOSTED-SUITE-START run={env["EQUIPO_STAGING_RUN_ID"]} scenarios={env["EQUIPO_STAGING_SCENARIOS"] or "all"} mode={modes[-1]}') |
| if report_mode != 'missing': |
| Path(env['EQUIPO_HEADLESS_REPORT']).write_text('{}' if report_mode == 'valid' else 'broken') |
| if fail: |
| @@ -104,10 +107,17 @@ class SuiteTest(unittest.TestCase): |
| os.environ.pop('EQUIPO_STAGING_TURN_LIMIT', None) |
| os.environ.pop('EQUIPO_STAGING_HOSTED_MODE', None) |
| os.environ['TMPDIR'] = str(root) |
| - ended = [] |
| + ended, run_ids = [], [] |
| def last(): |
| - ended.append((root / 'hosted-progress.log').read_text().splitlines()[-1].split(' at=')[0]) |
| + # The last line names the same run as the first; each |
| + # run has its own. |
| + lines = (root / 'hosted-progress.log').read_text().splitlines() |
| + run = re.match(r'^HOSTED-SUITE-START run=(\S+) ', lines[0]).group(1) |
| + self.assertTrue(lines[-1].startswith(f'HOSTED-SUITE run={run} '), lines[-1]) |
| + self.assertNotIn(run, run_ids) |
| + run_ids.append(run) |
| + ended.append(lines[-1].split(' at=')[0].replace(f' run={run}', '')) |
| staging.suite() |
| last() |
diff --git a/scripts/staging-thin.py b/scripts/staging-thin.py| index 66309a0f..625b4527 100755 |
| --- a/scripts/staging-thin.py |
| +++ b/scripts/staging-thin.py |
| @@ -637,9 +637,13 @@ def cleanup_suite(token, person): |
| time.sleep(2) |
| +def new_run_id(): |
| + return time.strftime('%Y%m%dT%H%M%SZ', time.gmtime()).lower() + '-' + secrets.token_hex(6) |
| + |
| + |
| @contextmanager |
| -def fresh_suite(): |
| - run_id = time.strftime('%Y%m%dT%H%M%SZ', time.gmtime()).lower() + '-' + secrets.token_hex(6) |
| +def fresh_suite(run_id=None): |
| + run_id = run_id or new_run_id() |
| person = 'suite-' + run_id + '@equipo-staging.invalid' |
| bindings = SUITE_ROOT / 'config/bindings.json' |
| original_bindings = json.loads(bindings.read_text()) |
| @@ -736,26 +740,29 @@ def suite(only='', mode=''): |
| which a drill watches: HOSTED-SUITE-START, the hosted scenarios' own |
| lines, then always one HOSTED-SUITE status=<ok|suite_failed|report_missing> |
| report=<the kept report or -> line; the report and the progress are |
| - kept per run (keep_run).""" |
| + kept per run (keep_run). Every line carries run=<run id> (the suite |
| + person's and EQUIPO_STAGING_RUN_ID), so one run's lines are never |
| + read as another's.""" |
| mode = mode or os.environ.get('EQUIPO_STAGING_HOSTED_MODE') or 'plain' |
| report, progress = ROOT / 'report.json', ROOT / 'hosted-progress.log' |
| report.unlink(missing_ok=True) |
| known = mode in HOSTED_MODES |
| if not known: |
| mode = re.sub(r'[^A-Za-z0-9_-]', '_', mode)[:40] or 'unknown' |
| - private(progress, f'HOSTED-SUITE-START scenarios={only or "all"} mode={mode} at={stamp()}\n') |
| + run_id = new_run_id() |
| + private(progress, f'HOSTED-SUITE-START run={run_id} scenarios={only or "all"} mode={mode} at={stamp()}\n') |
| started, failed = False, True |
| try: |
| if not known: |
| raise ValueError(f'mode {mode!r} is not one of {", ".join(HOSTED_MODES)}') |
| - with fresh_suite() as (run_id, token, cookie): |
| + with fresh_suite(run_id) as (run_id, token, cookie): |
| started = True |
| suite_run(only, run_id, token, cookie, mode, progress) |
| failed = False |
| finally: |
| status = run_status(report, started, failed) |
| kept, kept_progress = keep_run(only, mode, report) |
| - append(progress, f'HOSTED-SUITE status={status} report={kept or "-"} at={stamp()}') |
| + append(progress, f'HOSTED-SUITE run={run_id} status={status} report={kept or "-"} at={stamp()}') |
| private(kept_progress, progress.read_text()) |
| print(f'suite {status}; report {kept or "missing"}; progress {kept_progress}', flush=True) |