Skip to content

[local-test-e2e-worker-daemon-idle-auto-update] test(e2e): worker-daemon — idle auto-update installs a newer release and hands over - #852

Merged
danii1 merged 1 commit into
mainfrom
feature/local-test-e2e-worker-daemon-idle-auto-update
Dec 4, 2026
Merged

danii1 merged 1 commit into
mainfrom
feature/local-test-e2e-worker-daemon-idle-auto-update

Conversation

@danii1

@danii1 danii1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Why

Task local-test-e2e-worker-daemon-idle-auto-update: test(e2e): worker-daemon — idle auto-update installs a newer release and hands over

Nothing exercised the worker's idle self-update end to end. A broken update loop (installing mid-task, a crash loop after install, or never updating) could break every unattended worker at once. The e2e helpers force DEVINTERN_NO_UPDATE=1, so the path was never run.

What changed

  • packages/e2e/helpers/auto-update-fixture.ts (new) has AutoUpdateWorker, a WorkerFixture subclass. It copies the built dist to <tmp>/prefix/lib/node_modules/@getdevintern/code/ so install detection really returns npm-global.
    • It starts a loopback fake registry that serves latest = 99.0.0 and records requests.
    • It puts an npm shim first on PATH that logs its argv and exits 0 or 1.
    • It sets DEVINTERN_SERVICE=1 and removes DEVINTERN_NO_UPDATE.
  • packages/e2e/helpers/npm-registry-redirect-preload.cjs (new) redirects registry.npmjs.org to the fake. It also shortens the 60 s update tick to 1 s, following the existing preload pattern.
  • packages/e2e/helpers/worker.ts: two optional fixture options, daemonEntry and daemonArgs. They let a test run a different CLI entry and pass --no-update. This is a small change to shared test-helper code, not product code.
  • packages/e2e/tests/local/worker-auto-update.test.ts (new) has four tests:
    • (a) An idle worker with a newer latest calls the shim exactly once with install -g @getdevintern/code@99.0.0, logs "Updated devintern to 99.0.0", and exits 1 (the service-manager path).
    • (b) A busy worker running a slow agent task logs "waiting for idle" and makes no install until the task settles. It installs after that.
    • (c) [worker] auto_update = false and --no-update install nothing and poll nothing further.
    • (d) A failing install logs the failure and is not retried on later ticks. The worker keeps running and completes an injected task.
  • packages/e2e/docs/coverage/worker-daemon.md: the Auto-update row is now default with evidence and Missing items, last reviewed 2026-12-04. Backlog item 18 notes auto-update as covered. A Test notes entry describes the new test.

Scope

Included: gap e2e-worker-daemon-auto-update, scenarios (a), (b), (c) and (d). Excluded: the successor-spawn path used when no service manager is present, re-exec onto the new binary (the shim installs nothing), a real bun-global layout, launchd, and any product code change.

Tradeoffs

  • Tests set DEVINTERN_SERVICE=1 so the exit code is deterministic. The cost is that the successor-spawn handover is not covered, and the doc lists it as Missing.
  • The bundle is copied rather than symlinked, because install detection follows realpath and a symlink would land in packages/code and read as local. The copy is a few MB per worker and takes a moment.
  • Test (c) has to allow for one startup registry read (see Blast Radius).

Blast Radius

  • Only the e2e package and one area doc changed. WorkerFixture gained two optional fields that existing callers don't use, so they are unaffected.
  • Observed (unconfirmed intent), recorded in the doc: with [worker] auto_update = false, the CLI's non-installing startup update notice still reads the registry once. --no-update sends no request. The test asserts that exact current behavior.

Verification

  • bun run --filter @getdevintern/code build: passed.
  • bun run --filter @devintern/e2e test: 503 pass, 1 fail. The failure is worker doctor --json offers try-first-task… in worker-doctor.test.ts. It got run-foreground where it expected service, because this sandbox has no service manager. I did not touch that test, and I did not re-run it on the base commit. The 4 new tests pass; I ran that file standalone twice and it passed both times.
  • bun run --filter @devintern/e2e typecheck, lint and format:check: all clean.
  • Repo-wide bun run lint (including knip and the lint ratchet): the output I saw reached the knip and ratchet steps with no errors. It ended there, and I did not read a final exit status. The oxlint run printed a read-only filesystem warning.

🤖 Opened by DevIntern from local-test-e2e-worker-daemon-idle-auto-update

…e2e): worker-daemon — idle auto-update installs a newer release and hands over
@danii1 danii1 added the devintern-authored Pull request written by DevIntern working its own backlog label Dec 4, 2026
@danii1

danii1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Artifacts & verification

Run: 1727 · Commit: e62be68e0cf32f918f859c537f9e658db4a3c8f7

Verification report

Produced by __verify-1, execution 1 at e62be68e0cf32f918f859c537f9e658db4a3c8f7.

Show artifact
{
  "summary": "The implementation meets the task. All four scenarios are covered: (a) idle install and service-manager exit, (b) busy worker, (c) opt-outs, (d) install failure. `bun test tests/local/worker-auto-update.test.ts` passed 4 of 4 in about 20 s. The e2e typecheck, lint and format:check passed, and so did the repo-wide `bun run lint` (knip and lint ratchet). I did not re-run the `@getdevintern/code` build; `dist/index.js` already existed. I also did not run the full e2e suite. Blast radius: the only shared-code edit is two optional fields in `WorkerFixture` (`daemonEntry`, `daemonArgs`). Existing callers leave them unset, so they still use `cliPath` with no extra args. The new preload only loads for daemons started with `--preload`, and the redirect applies only to registry.npmjs.org. The area doc was updated within its own file only.",
  "items": [
    {
      "priority": "low",
      "confidence": "medium",
      "category": "testing",
      "file": "packages/e2e/helpers/auto-update-fixture.ts",
      "line": "63",
      "issue": "The successor-spawn path is not covered. The fixture sets DEVINTERN_SERVICE=1, so only the exit-1 service-manager branch is asserted. The task allows either, and the gap is documented under Missing.",
      "evidence": "auto-update-fixture.ts:63 env DEVINTERN_SERVICE; the doc Missing line lists this.",
      "suggestion": "Optionally add a successor-spawn test later, and kill the successor in finally."
    },
    {
      "priority": "info",
      "confidence": "high",
      "category": "testing",
      "file": "packages/e2e/tests/local/worker-auto-update.test.ts",
      "line": "88",
      "issue": "The opt-out test tolerates one registry read at startup when auto_update=false. The startup notice reads the registry once but never installs. The doc records this as 'Observed (unconfirmed intent)'.",
      "evidence": "Test run passed; the assertion is startupRequests <= 1, then no further requests across several 1 s ticks.",
      "suggestion": "None needed."
    }
  ],
  "approved": true
}

Auto-review summary

Produced by auto-review, execution 1 at e62be68e0cf32f918f859c537f9e658db4a3c8f7.

Show artifact
{
  "iterations": 0,
  "success": true,
  "finalFeedback": {
    "summary": "This PR adds an offline e2e test for idle worker auto-update. A new fixture copies the built bundle into a fake npm-global layout, and a Bun preload redirects registry requests to a loopback fake and shortens the 60 s tick to 1 s. A PATH-shimmed `npm` records its argv. The change touches only test helpers and docs. The one optional `WorkerFixture` change adds `daemonEntry` and `daemonArgs`, which default to the old behavior. The change is safe because production code is untouched and the preload only loads when `--preload` is passed. I read `worker-auto-update.ts:49,288,329` and confirmed it calls the global `setInterval(..., WORKER_AUTO_UPDATE_TICK_MS)` with the literal 60_000 and logs the 'waiting for idle' line the tests match. I did not run the tests, so that is checked by reading only, not by running.",
    "items": [
      {
        "priority": "low",
        "confidence": "medium",
        "category": "testing",
        "file": "packages/e2e/helpers/npm-registry-redirect-preload.cjs",
        "line": "18-20",
        "issue": "The preload shortens the tick by matching `delay === 60_000` on every `setInterval` in the daemon. If `WORKER_AUTO_UPDATE_TICK_MS` changes (`packages/code/src/lib/workspace/worker-auto-update.ts:49`), the tests only show up as 40 s timeouts, not a clear error. Any other 60 s interval would also be shortened. Today the only other 60000 interval I found is `lib/webhook/runtime.ts:49`, which the worker daemon does not appear to use.",
        "evidence": "worker-auto-update.ts:49,329; grep for 60_000/60000 intervals in packages/code/src.",
        "suggestion": "Add an env override such as `DEVINTERN_WORKER_UPDATE_TICK_MS` in the product code so the preload does not need to patch `setInterval`. Alternatively, have the preload log a line when it rewrites the interval."
      },
      {
        "priority": "low",
        "confidence": "low",
        "category": "testing",
        "file": "packages/e2e/tests/local/worker-auto-update.test.ts",
        "line": "84-92",
        "issue": "The opt-out test asserts the startup notice reads the registry at most once with `auto_update = false`. The docs call this 'observed (unconfirmed intent)'. This pins down behavior that may be accidental, and a later change that removes the request would not fail. Sleeping 3 s to show nothing further happens is time-based and weak proof, but acceptable at a 1 s tick.",
        "evidence": "Test lines 84-92 and the coverage doc 'Missing' note.",
        "suggestion": "Keep it, but if the startup read is later confirmed as intended, assert exactly 1. Otherwise drop the upper-bound assertion."
      },
      {
        "priority": "info",
        "confidence": "low",
        "category": "code-quality",
        "file": "packages/e2e/helpers/auto-update-fixture.ts",
        "line": "60-72",
        "issue": "The constructor calls `mkdtempSync` and `cpSync` before `super()`. The copy of `dist` is not removed if `super()` throws, and the temp root depends on `WorkerFixture.dispose()` to clean up. If `dispose` already removes `root`, this is fine. I did not verify that it does.",
        "evidence": "unproven",
        "suggestion": "Confirm that `WorkerFixture.dispose` removes the passed `root`. If it doesn't, remove it in the overridden `dispose`."
      },
      {
        "priority": "info",
        "confidence": "medium",
        "category": "documentation",
        "file": "packages/e2e/docs/coverage/worker-daemon.md",
        "line": "143",
        "issue": "The `~~Auto-update~~` strikethrough sits mid-sentence in the Priority 18 line. That makes it read as though auto-update were struck from scope rather than done.",
        "evidence": "Diff hunk at docs line 143.",
        "suggestion": "Reword it to 'launchd remains; auto-update is covered by `tests/local/worker-auto-update.test.ts`.'"
      }
    ],
    "approved": true
  },
  "unresolved": [],
  "stopReason": "approved",
  "commitSha": "e62be68e0cf32f918f859c537f9e658db4a3c8f7",
  "history": [
    {
      "iteration": 1,
      "feedback": {
        "summary": "This PR adds an offline e2e test for idle worker auto-update. A new fixture copies the built bundle into a fake npm-global layout, and a Bun preload redirects registry requests to a loopback fake and shortens the 60 s tick to 1 s. A PATH-shimmed `npm` records its argv. The change touches only test helpers and docs. The one optional `WorkerFixture` change adds `daemonEntry` and `daemonArgs`, which default to the old behavior. The change is safe because production code is untouched and the preload only loads when `--preload` is passed. I read `worker-auto-update.ts:49,288,329` and confirmed it calls the global `setInterval(..., WORKER_AUTO_UPDATE_TICK_MS)` with the literal 60_000 and logs the 'waiting for idle' line the tests match. I did not run the tests, so that is checked by reading only, not by running.",
        "items": [
          {
            "priority": "low",
            "confidence": "medium",
            "category": "testing",
            "file": "packages/e2e/helpers/npm-registry-redirect-preload.cjs",
            "line": "18-20",
            "issue": "The preload shortens the tick by matching `delay === 60_000` on every `setInterval` in the daemon. If `WORKER_AUTO_UPDATE_TICK_MS` changes (`packages/code/src/lib/workspace/worker-auto-update.ts:49`), the tests only show up as 40 s timeouts, not a clear error. Any other 60 s interval would also be shortened. Today the only other 60000 interval I found is `lib/webhook/runtime.ts:49`, which the worker daemon does not appear to use.",
            "evidence": "worker-auto-update.ts:49,329; grep for 60_000/60000 intervals in packages/code/src.",
            "suggestion": "Add an env override such as `DEVINTERN_WORKER_UPDATE_TICK_MS` in the product code so the preload does not need to patch `setInterval`. Alternatively, have the preload log a line when it rewrites the interval."
          },
          {
            "priority": "low",
            "confidence": "low",
            "category": "testing",
            "file": "packages/e2e/tests/local/worker-auto-update.test.ts",
            "line": "84-92",
            "issue": "The opt-out test asserts the startup notice reads the registry at most once with `auto_update = false`. The docs call this 'observed (unconfirmed intent)'. This pins down behavior that may be accidental, and a later change that removes the request would not fail. Sleeping 3 s to show nothing further happens is time-based and weak proof, but acceptable at a 1 s tick.",
            "evidence": "Test lines 84-92 and the coverage doc 'Missing' note.",
            "suggestion": "Keep it, but if the startup read is later confirmed as intended, assert exactly 1. Otherwise drop the upper-bound assertion."
          },
          {
            "priority": "info",
            "confidence": "low",
            "category": "code-quality",
            "file": "packages/e2e/helpers/auto-update-fixture.ts",
            "line": "60-72",
            "issue": "The constructor calls `mkdtempSync` and `cpSync` before `super()`. The copy of `dist` is not removed if `super()` throws, and the temp root depends on `WorkerFixture.dispose()` to clean up. If `dispose` already removes `root`, this is fine. I did not verify that it does.",
            "evidence": "unproven",
            "suggestion": "Confirm that `WorkerFixture.dispose` removes the passed `root`. If it doesn't, remove it in the overridden `dispose`."
          },
          {
            "priority": "info",
            "confidence": "medium",
            "category": "documentation",
            "file": "packages/e2e/docs/coverage/worker-daemon.md",
            "line": "143",
            "issue": "The `~~Auto-update~~` strikethrough sits mid-sentence in the Priority 18 line. That makes it read as though auto-update were struck from scope rather than done.",
            "evidence": "Diff hunk at docs line 143.",
            "suggestion": "Reword it to 'launchd remains; auto-update is covered by `tests/local/worker-auto-update.test.ts`.'"
          }
        ],
        "approved": true
      },
      "addressed": [],
      "commitSha": "e62be68e0cf32f918f859c537f9e658db4a3c8f7"
    }
  ]
}

@danii1
danii1 merged commit f88e501 into main Dec 4, 2026
1 check passed
@danii1
danii1 deleted the feature/local-test-e2e-worker-daemon-idle-auto-update branch December 4, 2026 14:24
@danii1

danii1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Auto-merge: merged (squash) at e62be68.

Every changed file is inside the workspace's safe paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merged devintern-authored Pull request written by DevIntern working its own backlog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant