Files
openclaude/knip.json
T
0xfandomandGitHub 3fb718f403 fix(worktree): base agent isolation worktree on parent HEAD, not origin/main (#1652)
* fix(worktree): base agent isolation worktree on parent HEAD, not origin/main

createAgentWorktree delegated to getOrCreateWorktree with no base, so the
non-PR path checked out origin/<defaultBranch> whenever that remote-tracking
ref existed locally. An isolated agent (isolation: "worktree") is expected
to see the same committed state as the parent session, but instead got an
older tree and missed files that exist only on the active branch.

Resolve the parent session's HEAD from the session cwd and thread it through
getOrCreateWorktree as a new `baseRef` option (used verbatim, then rev-parsed
to a SHA). Falls back to the prior origin-based behavior when HEAD can't be
resolved (e.g. a repo with no commits). EnterWorktree/PR worktree paths are
unchanged.

Fixes #1586

* test(worktree): make agent-base regression test hermetic; add explicit cwd seam

The integration test went through createAgentWorktree's ambient getCwd(),
which reads process-global cwd state. bun runs test files concurrently in one
process and a sibling test mutates that global cwd, so the agent-base test
raced and failed in the full suite (worktree based on origin/main, missing
the feature-only file).

Add an optional `cwd` to createAgentWorktree, used for both the canonical
git-root and the parent-HEAD lookups (defaults to getCwd()). The test pins it
explicitly so it no longer depends on the raced global cwd. Verified it passes
isolated and in the full src/utils suite, and still fails on the pre-fix code.

* test(worktree): isolate agent-base regression from leaked module mocks

Per review: the regression test imported createAgentWorktree (and thus
worktree.ts's execFileNoThrow.js dependency) at module load, so it could bind
process-global bun mock.module state left by a neighboring suite before
establishing its own isolation.

Hold the shared mutation lock for the whole test so it never runs interleaved
with suites that mock execFileNoThrow.js, and import the worktree module only
after the lock is held, via a cache-busted dynamic import, so the binding
resolves against the real module.

* test(worktree): use execa and a longer timeout in the agent-base regression

Per AGENTS.md, src/utils tests shell out via execa rather than child_process,
so swap the git() helper to execaSync. The test also performs real git work
(init, commit, branch, worktree add) that can exceed Bun's default 5s timeout
on slower/Windows runners, so give it an explicit 15s budget.

* test: stop two suites leaking partial module mocks process-wide

Bun's mock.module is process-global and is not reverted by mock.restore(), so a
partial-surface mock left active by one suite breaks any later suite that
imports the same module — it sees a module missing the un-mocked exports and
fails to link with "named export not found".

- setupGitHubActions.test.ts mocked config.js with only saveGlobalConfig.
  Spread the real surface (as it already does for execFileNoThrow/browser) and
  restore it in afterEach, so config.js keeps its full surface for later suites.
- osc.test.ts mocked execFileNoThrow.js and tempfile.js with partial stubs and
  never restored them. Spread the real surfaces and gate each overridden export
  on an active-suite flag, so when osc's tests aren't running the exports
  delegate to the real implementation instead of leaking stubs.

This unblocks worktree.agentBase.test.ts (which loads worktree.ts → config.js /
execFileNoThrow.js) when it runs after either suite.

* Revert mock-isolation changes that regressed the full test suite

The previous commit reworked the leaking config.js / execFileNoThrow.js mocks
in setupGitHubActions.test.ts and osc.test.ts (and swapped the worktree test
helper to execa). While it fixed the two-file reproductions, it regressed the
full smoke-and-tests run: createAgentWorktree began failing with "not in a git
repository" in the combined suite. Revert to the last green state while a more
robust isolation approach (process-level isolation for the real-git test) is
worked out.

* test(worktree): run the agent-base regression in an isolated process

The previous in-suite isolation attempts couldn't survive the full test run:
createAgentWorktree shells out to git via execFileNoThrow.js, which other
suites mock with `mock.module` — a process-global override Bun cannot reliably
revert, so any leaked stub made the test fail with "not in a git repository"
depending on suite ordering.

Move the actual createAgentWorktree call into a standalone child process
(worktree.agentBase.fixture.ts) that loads only the real modules, and keep the
git repo setup and assertions in the test using real git directly. Nothing the
shared test process mocks can reach the child, so the test is now order- and
leak-independent. Verified passing in isolation, alongside the two leaking
suites that previously broke it, and in the full suite.

* test(worktree): register agent-base fixture as a knip entrypoint

The agent-base regression runs createAgentWorktree in a standalone child
process (worktree.agentBase.fixture.ts) to escape leaked module mocks. knip
sees no static importer for it — it is spawned via execFileSync — and the
deadcode check fails it as an unused file. It is a genuine process
entrypoint, so add the *.fixture.ts glob to knip's entry list.
2026-06-25 06:23:48 +08:00

37 lines
1.0 KiB
JSON

{
"$schema": "https://unpkg.com/knip@6/schema.json",
"entry": [
"src/entrypoints/cli.tsx",
"src/entrypoints/mcp.ts",
"src/entrypoints/init.ts",
"src/entrypoints/sdk/index.ts",
"src/main.tsx",
"scripts/**/*.ts",
"bin/openclaude",
"src/**/*.test.{ts,tsx}",
"src/**/*.fixture.ts",
"src/**/__tests__/**/*.{ts,tsx}",
"tests/**/*.test.ts"
],
"project": ["src/**/*.{ts,tsx}", "scripts/**/*.ts"],
"ignore": [
"src/integrations/generated/**",
"src/services/internalLogging.ts",
"src/types/generated/**",
"src/test/fixtures/**",
"src/tools/REPLTool/**",
"src/tools/TungstenTool/**",
"src/tools/SuggestBackgroundPRTool/**",
"src/tools/VerifyPlanExecutionTool/**",
"src/commands/agents-platform/**",
"src/assistant/AssistantSessionChooser.tsx",
"src/commands/assistant/AssistantSessionChooser.ts",
"src/utils/protectedNamespace.ts",
"src/utils/providerAutoDetect.ts"
],
"ignoreDependencies": [
"@types/bun",
"@anthropic-ai/foundry-sdk"
]
}