Skip to content

native pi e2e (#1239) + fix one-shot stamp race (#1243) - #1246

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-24_native-e2e-pi
Sep 24, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-24_native-e2e-pi

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Closes the pi-lane gap from #1239 and fixes a real bug the new suite caught immediately.

test: native pi e2e (Refs #1239)

tests/e2e/fake-upstream-chat.mjs — deterministic chat-completions fake: scripted tool_calls driven by marker directives in the last user message (请调用<tool> / 请调用<tool> {json}), stream + non-stream shapes, JSONL oracle (plugin/conv headers, tools, roles, acp tag counts, tool results).

tests/e2e/e2e-native-pi.test.ts (ACP_TEST_E2E_NATIVE=1, zero tokens) — drives the real pi CLI in package-native mode (repo root loaded as a pi package = the bili plugin install pi lane) and asserts #1239's acceptance list:

  1. traffic intercepted + plugin-mode claimed — every upstream request carries x-bili-plugin: pi + conversation header
  2. /acp command exits clean and the /__bili/plugin/status endpoint it consumes answers live
  3. acp_status executes and its result (the status report) is re-sent in history
  4. compress executes and compression actually happens: result string reports the fold, proxy logs the plugin-channel execution, persisted session carries ≥1 block after graceful stop

Mechanics: hermetic PI_CODING_AGENT_DIR + XDG + spawn cwd outside the repo (#815); run 1 loads ~7.6KB filler (kernel protected-zone + 5000-char minimum), run 2 (--continue) scripts the compress round. Sessions persist lazily → suite SIGTERMs the hermetic proxy before on-disk assertions.

fix: #1243 one-shot stamp race (Fixes #1243)

A native-lane pi -p fires before_provider_headers exactly once, inside the async proxy-bootstrap window — BILLION_CONTEXT_PROXY not yet written → no x-bili-plugin stamp → the session binds anonymous wire mode for the whole process (found live while building this suite; verified by the new per-request stamp assertions failing on master and passing with the fix).

Reader awaits writer: pi-native registers a NativeOriginWaiter (readyOrigin(state)) with native-bootstrap; the shared factory handler awaits awaitNativeProxyOrigin() when the base is unresolved. No waiter registered (wire/launcher hosts) → immediate undefined, zero added latency.

Also documents the cleanEnv() lesson: the node:test runner exports NODE_TEST_CONTEXT into spawned children and pi-native.ts deliberately stands down inside node:test — the suite must strip it or it exercises a disabled bootstrap.

Pre-flight

  • npm run typecheck ✅
  • npm run build ✅ (dist restored pristine after canary experiments — verified by diff)
  • ACP_TEST_E2E_NATIVE=1 node --import tsx --test tests/e2e/e2e-native-pi.test.ts → 4/4 pass, ×4 consecutive runs
  • focused unit suites (pi-native/plugin-agent/update-dsh-self-refresh): 64 pass, 3 fail — identical 3 fail on stashed pristine master (pre-existing sandbox artifact, CI covers)
  • full npm test has known sandbox hangs (pre-existing; master same)

Notes

A native-lane 'pi -p' fires before_provider_headers exactly once, inside
the async proxy bootstrap window: BILLION_CONTEXT_PROXY is not written
yet, proxyBaseForCtx() resolves undefined and the handler returns — the
x-bili-plugin / x-bili-plugin-conversation headers are never stamped and
the session binds anonymous wire mode for the whole process.

Reader awaits writer: pi-native registers a NativeOriginWaiter
(readyOrigin(state)) with native-bootstrap; the shared factory's
before_provider_headers awaits awaitNativeProxyOrigin() whenever the
base is unresolved. Hosts without a native entry register no waiter and
get an immediate undefined — zero added latency for wire/launcher modes.
…ream (#1239)

fake-upstream-chat.mjs: chat-completions fake with scripted tool_calls
(marker directives in the last user message, queue-per-user-turn, stream
+ non-stream) and a JSONL oracle (headers, tools, roles, tool results).

e2e-native-pi.test.ts (ACP_TEST_E2E_NATIVE=1): hermetic PI_CODING_AGENT_DIR
+ XDG + spawn-cwd outside the repo (#815); asserts #1239's acceptance —
interception + per-request x-bili-plugin stamp (#1243), /acp exit-clean
with a live /__bili/plugin/status endpoint, acp_status executes and
returns the status report, compress executes and the fold lands
(result string + proxy log + persisted blocks after graceful stop).

cleanEnv() must strip NODE_TEST_CONTEXT: the node:test runner exports it
into spawned children and pi-native deliberately stands down inside
node:test — without this the suite exercises a disabled bootstrap.

CI: ci-e2e-native.yml runs the suite on every PR with pi pinned
(pi-stable@0.83.6, same discipline as the codex pin #815).
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-24_native-e2e-pi (b035532)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1246

Each push to this PR publishes a new version under the pr-1246 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1246.tgz
npm install -g package

Install instructions are refreshed on each push.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native pi one-shot (-p): first request races the proxy bootstrap — x-bili-plugin never stamped, session binds anonymous wire mode

1 participant