Skip to content

[local-isolate-worker-init-unit-tests-from-the] Isolate worker-init unit tests from the host GITHUB_TOKEN - #857

Merged
danii1 merged 1 commit into
mainfrom
feature/local-isolate-worker-init-unit-tests-from-the
Dec 4, 2026
Merged

danii1 merged 1 commit into
mainfrom
feature/local-isolate-worker-init-unit-tests-from-the

Conversation

@danii1

@danii1 danii1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Why

Task local-isolate-worker-init-unit-tests-from-the: Isolate worker-init unit tests from the host GITHUB_TOKEN

worker-init.test.ts failed whenever GITHUB_TOKEN was set in the host environment, and the DevIntern worker exports it to every agent run. runWorkerInit correctly reuses an existing token and skips the token prompt. The test's scripted answers (ghp_test, then an empty line) then shifted by one, so ghp_test was consumed as the task query. The test was reading the real process environment, not an isolated one.

What changed

In packages/code/tests/setup/worker-env.ts, I added host GitHub credentials to the shared WORKER_INJECTED_ENV_VARS list: GITHUB_TOKEN, GH_TOKEN, GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_BASE64 and GITHUB_APP_PRIVATE_KEY_PATH. That list is already applied in two places:

  • the per-file preload (guard-worker-env.ts) strips it from in-process test code;
  • run-tests.ts strips it from the environment of spawned CLI children.

This fixes the whole class of leaks at the isolation layer, so no test or product code changed.

Scope

Included: the test isolation list only. Excluded: onboarding behavior (reusing an existing GITHUB_TOKEN stays as is), runWorkerInit, and the individual worker-init tests. I did not check whether other tracker credentials, such as Jira or Linear tokens, leak into tests in the same way.

Tradeoffs

The scrub is broad, so any test that relied on an ambient GITHUB_TOKEN would now fail. None did: the full suite passes. The cost is that a test needing a token must set it itself. I chose this over pinning env in the deps() helper because it also covers sibling tests and future ones.

Blast Radius

This affects every packages/code test process and any CLI child the tests spawn. Production code is untouched. I did not grep the tests for ones that assert on these variables being absent.

Verification

All run from packages/code unless noted.

  • GITHUB_TOKEN=ghp_dummy bun run test tests/worker-init.test.ts: 107 pass, 0 fail.
  • GITHUB_TOKEN=ghp_dummy GH_TOKEN=x bun run test (full suite): 6527 pass, 0 fail.
  • env -u GITHUB_TOKEN bun run test (full suite): 6527 pass, 0 fail.
  • bun run typecheck and bun run lint from the repo root: both exit 0.
  • Not run: the single-file env -u GITHUB_TOKEN command on its own, and the offline e2e tests. The unset case is covered by the full-suite run.

🤖 Opened by DevIntern from local-isolate-worker-init-unit-tests-from-the

…te worker-init unit tests from the host GITHUB_TOKEN
@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: 1736 · Commit: 5f0afb940b5782867584221e6c41597450b9cc12

Verification report

Produced by __verify-1, execution 1 at 5f0afb940b5782867584221e6c41597450b9cc12.

Show artifact
{
  "summary": "The change adds GITHUB_TOKEN, GH_TOKEN, GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_BASE64 and GITHUB_APP_PRIVATE_KEY_PATH to WORKER_INJECTED_ENV_VARS in tests/setup/worker-env.ts. The existing preload already strips that list, so host GitHub credentials are now scrubbed for every unit test. That is the isolation-layer fix the task preferred. I ran the checks. `GITHUB_TOKEN=[redacted] bun run test tests/worker-init.test.ts` gave 107 pass and 0 fail. `env -u GITHUB_TOKEN` on the same file also gave 107 pass and 0 fail. The full packages/code suite gave 6527 pass, 7 skip, 0 fail with GITHUB_TOKEN and GH_TOKEN set, and the same counts with GITHUB_TOKEN unset. The only other consumer of the list, tests/worker-env-guard.test.ts, iterates it generically, so adding entries cannot break it. No product code changed, and onboarding still reuses an existing GITHUB_TOKEN. I did not run `bun run typecheck` or `bun run lint`. The diff only adds string literals to an existing `as const` array, so I expect no impact on either. Tests that need a token must set it themselves, and the full suite passing shows none relied on the host value.",
  "items": [
    {
      "priority": "info",
      "confidence": "medium",
      "category": "testing",
      "file": "packages/code/tests/setup/worker-env.ts",
      "line": "64",
      "issue": "The list is named WORKER_INJECTED_ENV_VARS, but the new entries are host credentials, so the name is slightly broader than before. Nothing asserts that GITHUB_TOKEN is stripped (worker-env-guard.test.ts covers only some names).",
      "evidence": "tests/worker-env-guard.test.ts:15-33 and 81-82 assert specific names. The loop at line 47 covers every entry, so the new ones are exercised generically.",
      "suggestion": "Optionally add `expect(WORKER_INJECTED_ENV_VARS).toContain(\"GITHUB_TOKEN\")` to the guard test so the regression is pinned explicitly."
    }
  ],
  "approved": true
}

Auto-review summary

Produced by auto-review, execution 1 at 5f0afb940b5782867584221e6c41597450b9cc12.

Show artifact
{
  "iterations": 0,
  "success": true,
  "finalFeedback": {
    "summary": "The PR adds five host GitHub credential variables (GITHUB_TOKEN, GH_TOKEN, GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_BASE64, GITHUB_APP_PRIVATE_KEY_PATH) to WORKER_INJECTED_ENV_VARS. The per-file preload guard and run-tests.ts both strip these names before tests run. The change is safe because the list is test-only: its only consumers are tests/setup/worker-env.ts (stripWorkerInjectedEnv), tests/worker-env-guard.test.ts, and the preload referenced in bunfig.toml:31. I ran the full suite with GITHUB_TOKEN, GH_TOKEN and GITHUB_APP_ID set in the host env. It finished with 6527 pass, 7 skip and 0 fail. The suite does not prove the stripping itself, because worker-init-onboarding and worker-env-guard passed in the targeted run, and the full run only shows nothing relied on those inherited values. The guard test loops over the list generically, so the new entries are covered, but no test names the new variables explicitly.",
    "items": [
      {
        "priority": "low",
        "confidence": "medium",
        "category": "testing",
        "file": "packages/code/tests/worker-env-guard.test.ts",
        "line": "15-33",
        "issue": "Existing tests assert specific names are in the list (e.g. DEVINTERN_WORKER_SUBPROCESS, RUN_ID_ENV). None pins GITHUB_TOKEN, so a later edit could drop it and reintroduce the worker-init prompt shift. The generic loop at line 47 would still pass.",
        "evidence": "tests/worker-env-guard.test.ts:15-33,47,81-82 are the only pinned-name assertions, and none mention GITHUB_TOKEN. The loop at line 47 iterates whatever the list contains.",
        "suggestion": "Add expect(WORKER_INJECTED_ENV_VARS).toContain('GITHUB_TOKEN') and the other four credential names, in the style of the existing assertions."
      },
      {
        "priority": "info",
        "confidence": "medium",
        "category": "code-quality",
        "file": "packages/code/tests/setup/worker-env.ts",
        "line": "64-72",
        "issue": "Some tests that run the e2e or CLI helpers may expect a real host token to reach spawned subprocesses. run-tests.ts also calls stripWorkerInjectedEnv, so any such test must now set the token explicitly. The full suite passed with tokens set, so nothing in packages/code depends on the inheritance. The offline e2e tests in packages/e2e are outside the suite I ran.",
        "evidence": "Full packages/code suite passed: 6527 pass, 0 fail, with GITHUB_TOKEN, GH_TOKEN and GITHUB_APP_ID set. packages/e2e not run.",
        "suggestion": "If any packages/e2e/tests/local test spawns the CLI and reads the host GITHUB_TOKEN, run it once with a token set to confirm."
      }
    ],
    "approved": true
  },
  "unresolved": [],
  "stopReason": "approved",
  "commitSha": "5f0afb940b5782867584221e6c41597450b9cc12",
  "history": [
    {
      "iteration": 1,
      "feedback": {
        "summary": "The PR adds five host GitHub credential variables (GITHUB_TOKEN, GH_TOKEN, GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_BASE64, GITHUB_APP_PRIVATE_KEY_PATH) to WORKER_INJECTED_ENV_VARS. The per-file preload guard and run-tests.ts both strip these names before tests run. The change is safe because the list is test-only: its only consumers are tests/setup/worker-env.ts (stripWorkerInjectedEnv), tests/worker-env-guard.test.ts, and the preload referenced in bunfig.toml:31. I ran the full suite with GITHUB_TOKEN, GH_TOKEN and GITHUB_APP_ID set in the host env. It finished with 6527 pass, 7 skip and 0 fail. The suite does not prove the stripping itself, because worker-init-onboarding and worker-env-guard passed in the targeted run, and the full run only shows nothing relied on those inherited values. The guard test loops over the list generically, so the new entries are covered, but no test names the new variables explicitly.",
        "items": [
          {
            "priority": "low",
            "confidence": "medium",
            "category": "testing",
            "file": "packages/code/tests/worker-env-guard.test.ts",
            "line": "15-33",
            "issue": "Existing tests assert specific names are in the list (e.g. DEVINTERN_WORKER_SUBPROCESS, RUN_ID_ENV). None pins GITHUB_TOKEN, so a later edit could drop it and reintroduce the worker-init prompt shift. The generic loop at line 47 would still pass.",
            "evidence": "tests/worker-env-guard.test.ts:15-33,47,81-82 are the only pinned-name assertions, and none mention GITHUB_TOKEN. The loop at line 47 iterates whatever the list contains.",
            "suggestion": "Add expect(WORKER_INJECTED_ENV_VARS).toContain('GITHUB_TOKEN') and the other four credential names, in the style of the existing assertions."
          },
          {
            "priority": "info",
            "confidence": "medium",
            "category": "code-quality",
            "file": "packages/code/tests/setup/worker-env.ts",
            "line": "64-72",
            "issue": "Some tests that run the e2e or CLI helpers may expect a real host token to reach spawned subprocesses. run-tests.ts also calls stripWorkerInjectedEnv, so any such test must now set the token explicitly. The full suite passed with tokens set, so nothing in packages/code depends on the inheritance. The offline e2e tests in packages/e2e are outside the suite I ran.",
            "evidence": "Full packages/code suite passed: 6527 pass, 0 fail, with GITHUB_TOKEN, GH_TOKEN and GITHUB_APP_ID set. packages/e2e not run.",
            "suggestion": "If any packages/e2e/tests/local test spawns the CLI and reads the host GITHUB_TOKEN, run it once with a token set to confirm."
          }
        ],
        "approved": true
      },
      "addressed": [],
      "commitSha": "5f0afb940b5782867584221e6c41597450b9cc12"
    }
  ]
}

@danii1

danii1 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

🛑 Auto-merge: left open for human review (checked 5f0afb9).

packages/code/tests/setup/worker-env.ts matches the deny path packages/code/tests/setup/**, so this pull request is never auto-merged. Review and merge it yourself.

devintern checks again after new commits or a change to the auto-merge policy.

@danii1
danii1 merged commit 618d296 into main Dec 4, 2026
1 check passed
@danii1
danii1 deleted the feature/local-isolate-worker-init-unit-tests-from-the branch December 4, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devintern-authored Pull request written by DevIntern working its own backlog needs-human-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant