oh-my-copilot 5.18.0 → 5.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -3
- package/bridge/__pycache__/gyoshu_bridge.cpython-314.pyc +0 -0
- package/bridge/claude-md-coordinator.cjs +2 -2
- package/bridge/cli.cjs +17691 -14571
- package/bridge/mcp-server.cjs +4624 -1922
- package/bridge/runtime-cli.cjs +2735 -757
- package/bridge/team-bridge.cjs +357 -139
- package/bridge/team-mcp.cjs +922 -645
- package/bridge/team.js +2851 -874
- package/dist/__tests__/delegation-enforcer.test.js +1 -1
- package/dist/__tests__/delegation-enforcer.test.js.map +1 -1
- package/dist/__tests__/hud/cli-diagnostic.test.js +1 -1
- package/dist/__tests__/hud/cli-diagnostic.test.js.map +1 -1
- package/dist/__tests__/pre-tool-enforcer.test.js +3 -0
- package/dist/__tests__/pre-tool-enforcer.test.js.map +1 -1
- package/dist/__tests__/session-start-script-context.test.js +1 -1
- package/dist/__tests__/session-start-script-context.test.js.map +1 -1
- package/dist/__tests__/skills.test.js +9 -0
- package/dist/__tests__/skills.test.js.map +1 -1
- package/dist/cli/commands/__tests__/smoke-cassette.test.d.ts +2 -0
- package/dist/cli/commands/__tests__/smoke-cassette.test.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/smoke-cassette.test.js +135 -0
- package/dist/cli/commands/__tests__/smoke-cassette.test.js.map +1 -0
- package/dist/cli/commands/smoke.d.ts +41 -2
- package/dist/cli/commands/smoke.d.ts.map +1 -1
- package/dist/cli/commands/smoke.js +103 -6
- package/dist/cli/commands/smoke.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +30 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/copilot-run/__tests__/job.test.js +347 -2
- package/dist/copilot-run/__tests__/job.test.js.map +1 -1
- package/dist/copilot-run/__tests__/sandbox-session.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/sandbox-session.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/sandbox-session.test.js +181 -0
- package/dist/copilot-run/__tests__/sandbox-session.test.js.map +1 -0
- package/dist/copilot-run/__tests__/sandbox.test.js +128 -4
- package/dist/copilot-run/__tests__/sandbox.test.js.map +1 -1
- package/dist/copilot-run/job.d.ts +87 -13
- package/dist/copilot-run/job.d.ts.map +1 -1
- package/dist/copilot-run/job.js +517 -177
- package/dist/copilot-run/job.js.map +1 -1
- package/dist/copilot-run/sandbox-session.d.ts +71 -0
- package/dist/copilot-run/sandbox-session.d.ts.map +1 -0
- package/dist/copilot-run/sandbox-session.js +156 -0
- package/dist/copilot-run/sandbox-session.js.map +1 -0
- package/dist/copilot-run/sandbox.d.ts +17 -0
- package/dist/copilot-run/sandbox.d.ts.map +1 -1
- package/dist/copilot-run/sandbox.js +108 -4
- package/dist/copilot-run/sandbox.js.map +1 -1
- package/dist/copilot-run/timeout.d.ts +4 -0
- package/dist/copilot-run/timeout.d.ts.map +1 -0
- package/dist/copilot-run/timeout.js +10 -0
- package/dist/copilot-run/timeout.js.map +1 -0
- package/dist/factory/check/__tests__/cli-ado.test.d.ts +2 -0
- package/dist/factory/check/__tests__/cli-ado.test.d.ts.map +1 -0
- package/dist/factory/check/__tests__/cli-ado.test.js +95 -0
- package/dist/factory/check/__tests__/cli-ado.test.js.map +1 -0
- package/dist/factory/check/__tests__/cli.test.js +2 -1
- package/dist/factory/check/__tests__/cli.test.js.map +1 -1
- package/dist/factory/check/cli.d.ts +17 -1
- package/dist/factory/check/cli.d.ts.map +1 -1
- package/dist/factory/check/cli.js +20 -2
- package/dist/factory/check/cli.js.map +1 -1
- package/dist/factory/heal/__tests__/logs-ado.test.d.ts +2 -0
- package/dist/factory/heal/__tests__/logs-ado.test.d.ts.map +1 -0
- package/dist/factory/heal/__tests__/logs-ado.test.js +39 -0
- package/dist/factory/heal/__tests__/logs-ado.test.js.map +1 -0
- package/dist/factory/heal/classify.d.ts +3 -1
- package/dist/factory/heal/classify.d.ts.map +1 -1
- package/dist/factory/heal/classify.js +4 -2
- package/dist/factory/heal/classify.js.map +1 -1
- package/dist/factory/heal/cli.d.ts +8 -2
- package/dist/factory/heal/cli.d.ts.map +1 -1
- package/dist/factory/heal/cli.js +11 -9
- package/dist/factory/heal/cli.js.map +1 -1
- package/dist/factory/heal/debug-lane.js +1 -1
- package/dist/factory/heal/debug-lane.js.map +1 -1
- package/dist/factory/heal/heal-evidence.d.ts +4 -2
- package/dist/factory/heal/heal-evidence.d.ts.map +1 -1
- package/dist/factory/heal/heal-evidence.js +8 -6
- package/dist/factory/heal/heal-evidence.js.map +1 -1
- package/dist/factory/heal/logs.d.ts +1 -1
- package/dist/factory/heal/logs.d.ts.map +1 -1
- package/dist/factory/heal/logs.js +4 -3
- package/dist/factory/heal/logs.js.map +1 -1
- package/dist/factory/heal/run.d.ts +3 -0
- package/dist/factory/heal/run.d.ts.map +1 -1
- package/dist/factory/heal/run.js +1 -1
- package/dist/factory/heal/run.js.map +1 -1
- package/dist/factory/run/__tests__/engine.sandbox.test.js +30 -2
- package/dist/factory/run/__tests__/engine.sandbox.test.js.map +1 -1
- package/dist/factory/run/__tests__/engine.test.js +31 -1
- package/dist/factory/run/__tests__/engine.test.js.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.d.ts +2 -0
- package/dist/factory/run/__tests__/fake-lanes.d.ts.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.js +1 -1
- package/dist/factory/run/__tests__/fake-lanes.js.map +1 -1
- package/dist/factory/run/__tests__/merge-policy.test.d.ts +2 -0
- package/dist/factory/run/__tests__/merge-policy.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/merge-policy.test.js +40 -0
- package/dist/factory/run/__tests__/merge-policy.test.js.map +1 -0
- package/dist/factory/run/__tests__/prepare-gates.test.js +22 -0
- package/dist/factory/run/__tests__/prepare-gates.test.js.map +1 -1
- package/dist/factory/run/__tests__/units.test.js +12 -1
- package/dist/factory/run/__tests__/units.test.js.map +1 -1
- package/dist/factory/run/engine.d.ts.map +1 -1
- package/dist/factory/run/engine.js +32 -6
- package/dist/factory/run/engine.js.map +1 -1
- package/dist/factory/run/lane-commit.d.ts +10 -1
- package/dist/factory/run/lane-commit.d.ts.map +1 -1
- package/dist/factory/run/lane-commit.js +21 -4
- package/dist/factory/run/lane-commit.js.map +1 -1
- package/dist/factory/run/merge-policy.d.ts +3 -1
- package/dist/factory/run/merge-policy.d.ts.map +1 -1
- package/dist/factory/run/merge-policy.js +8 -2
- package/dist/factory/run/merge-policy.js.map +1 -1
- package/dist/factory/run/review-guard.d.ts +2 -0
- package/dist/factory/run/review-guard.d.ts.map +1 -1
- package/dist/factory/run/review-guard.js +1 -1
- package/dist/factory/run/review-guard.js.map +1 -1
- package/dist/factory/run/state.d.ts +13 -0
- package/dist/factory/run/state.d.ts.map +1 -1
- package/dist/factory/run/state.js +20 -5
- package/dist/factory/run/state.js.map +1 -1
- package/dist/features/builtin-skills/skills.js +1 -1
- package/dist/features/builtin-skills/skills.js.map +1 -1
- package/dist/features/delegation-enforcer.d.ts.map +1 -1
- package/dist/features/delegation-enforcer.js +2 -6
- package/dist/features/delegation-enforcer.js.map +1 -1
- package/dist/forge/__tests__/gh-argv-baseline.heal.test.js +52 -2
- package/dist/forge/__tests__/gh-argv-baseline.heal.test.js.map +1 -1
- package/dist/forge/ado/__tests__/acceptance-scripts.test.d.ts +8 -0
- package/dist/forge/ado/__tests__/acceptance-scripts.test.d.ts.map +1 -0
- package/dist/forge/ado/__tests__/acceptance-scripts.test.js +567 -0
- package/dist/forge/ado/__tests__/acceptance-scripts.test.js.map +1 -0
- package/dist/forge/ado/__tests__/az-binary.test.js +4 -0
- package/dist/forge/ado/__tests__/az-binary.test.js.map +1 -1
- package/dist/forge/ado/__tests__/failed-jobs.test.d.ts +2 -0
- package/dist/forge/ado/__tests__/failed-jobs.test.d.ts.map +1 -0
- package/dist/forge/ado/__tests__/failed-jobs.test.js +96 -0
- package/dist/forge/ado/__tests__/failed-jobs.test.js.map +1 -0
- package/dist/forge/ado/az-binary.d.ts +2 -1
- package/dist/forge/ado/az-binary.d.ts.map +1 -1
- package/dist/forge/ado/az-binary.js +3 -2
- package/dist/forge/ado/az-binary.js.map +1 -1
- package/dist/forge/ado/checks.d.ts.map +1 -1
- package/dist/forge/ado/checks.js +30 -0
- package/dist/forge/ado/checks.js.map +1 -1
- package/dist/forge/github/ci.d.ts +2 -0
- package/dist/forge/github/ci.d.ts.map +1 -1
- package/dist/forge/github/ci.js +3 -0
- package/dist/forge/github/ci.js.map +1 -1
- package/dist/forge/types.d.ts +2 -0
- package/dist/forge/types.d.ts.map +1 -1
- package/dist/hooks/autopilot/__tests__/pipeline.test.js +1 -1
- package/dist/hooks/autopilot/__tests__/pipeline.test.js.map +1 -1
- package/dist/hooks/autopilot/adapters/execution-adapter.js +3 -3
- package/dist/hooks/autopilot/adapters/execution-adapter.js.map +1 -1
- package/dist/hooks/keyword-detector/__tests__/index.test.js +4 -0
- package/dist/hooks/keyword-detector/__tests__/index.test.js.map +1 -1
- package/dist/hooks/keyword-detector/__tests__/jev-shadow.test.js +7 -0
- package/dist/hooks/keyword-detector/__tests__/jev-shadow.test.js.map +1 -1
- package/dist/hooks/keyword-detector/index.d.ts +1 -1
- package/dist/hooks/keyword-detector/index.js +4 -4
- package/dist/hooks/keyword-detector/index.js.map +1 -1
- package/dist/hooks/keyword-detector/jev-shadow.js +1 -1
- package/dist/hooks/keyword-detector/jev-shadow.js.map +1 -1
- package/dist/hud/index.js +1 -1
- package/dist/hud/index.js.map +1 -1
- package/dist/mcp/__tests__/host-smoke-tool.test.js +14 -0
- package/dist/mcp/__tests__/host-smoke-tool.test.js.map +1 -1
- package/dist/ship/gates.d.ts +9 -3
- package/dist/ship/gates.d.ts.map +1 -1
- package/dist/ship/gates.js +24 -7
- package/dist/ship/gates.js.map +1 -1
- package/dist/smoke/__tests__/copilot-sdk-driver.test.js +129 -4
- package/dist/smoke/__tests__/copilot-sdk-driver.test.js.map +1 -1
- package/dist/smoke/__tests__/copilot-session-env.test.d.ts +2 -0
- package/dist/smoke/__tests__/copilot-session-env.test.d.ts.map +1 -0
- package/dist/smoke/__tests__/copilot-session-env.test.js +29 -0
- package/dist/smoke/__tests__/copilot-session-env.test.js.map +1 -0
- package/dist/smoke/__tests__/copilot-team-scenario.test.js +3 -0
- package/dist/smoke/__tests__/copilot-team-scenario.test.js.map +1 -1
- package/dist/smoke/copilot-sdk-driver.d.ts +37 -1
- package/dist/smoke/copilot-sdk-driver.d.ts.map +1 -1
- package/dist/smoke/copilot-sdk-driver.js +114 -10
- package/dist/smoke/copilot-sdk-driver.js.map +1 -1
- package/dist/smoke/copilot-sdk-scenarios.d.ts +27 -0
- package/dist/smoke/copilot-sdk-scenarios.d.ts.map +1 -1
- package/dist/smoke/copilot-sdk-scenarios.js +31 -0
- package/dist/smoke/copilot-sdk-scenarios.js.map +1 -1
- package/dist/smoke/copilot-session-env.d.ts +38 -1
- package/dist/smoke/copilot-session-env.d.ts.map +1 -1
- package/dist/smoke/copilot-session-env.js +82 -1
- package/dist/smoke/copilot-session-env.js.map +1 -1
- package/dist/smoke/copilot-smoke.d.ts +21 -1
- package/dist/smoke/copilot-smoke.d.ts.map +1 -1
- package/dist/smoke/copilot-smoke.js +86 -6
- package/dist/smoke/copilot-smoke.js.map +1 -1
- package/dist/smoke/copilot-team-scenario.d.ts +4 -2
- package/dist/smoke/copilot-team-scenario.d.ts.map +1 -1
- package/dist/smoke/copilot-team-scenario.js +5 -4
- package/dist/smoke/copilot-team-scenario.js.map +1 -1
- package/dist/smoke/replay/__tests__/cassette.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/cassette.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/cassette.test.js +387 -0
- package/dist/smoke/replay/__tests__/cassette.test.js.map +1 -0
- package/dist/smoke/replay/__tests__/handler.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/handler.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/handler.test.js +367 -0
- package/dist/smoke/replay/__tests__/handler.test.js.map +1 -0
- package/dist/smoke/replay/__tests__/matcher.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/matcher.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/matcher.test.js +318 -0
- package/dist/smoke/replay/__tests__/matcher.test.js.map +1 -0
- package/dist/smoke/replay/__tests__/normalize.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/normalize.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/normalize.test.js +53 -0
- package/dist/smoke/replay/__tests__/normalize.test.js.map +1 -0
- package/dist/smoke/replay/__tests__/redact.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/redact.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/redact.test.js +453 -0
- package/dist/smoke/replay/__tests__/redact.test.js.map +1 -0
- package/dist/smoke/replay/__tests__/run.test.d.ts +2 -0
- package/dist/smoke/replay/__tests__/run.test.d.ts.map +1 -0
- package/dist/smoke/replay/__tests__/run.test.js +311 -0
- package/dist/smoke/replay/__tests__/run.test.js.map +1 -0
- package/dist/smoke/replay/cassette.d.ts +210 -0
- package/dist/smoke/replay/cassette.d.ts.map +1 -0
- package/dist/smoke/replay/cassette.js +580 -0
- package/dist/smoke/replay/cassette.js.map +1 -0
- package/dist/smoke/replay/handler.d.ts +221 -0
- package/dist/smoke/replay/handler.d.ts.map +1 -0
- package/dist/smoke/replay/handler.js +702 -0
- package/dist/smoke/replay/handler.js.map +1 -0
- package/dist/smoke/replay/matcher.d.ts +194 -0
- package/dist/smoke/replay/matcher.d.ts.map +1 -0
- package/dist/smoke/replay/matcher.js +344 -0
- package/dist/smoke/replay/matcher.js.map +1 -0
- package/dist/smoke/replay/normalize.d.ts +35 -0
- package/dist/smoke/replay/normalize.d.ts.map +1 -0
- package/dist/smoke/replay/normalize.js +64 -0
- package/dist/smoke/replay/normalize.js.map +1 -0
- package/dist/smoke/replay/redact.d.ts +151 -0
- package/dist/smoke/replay/redact.d.ts.map +1 -0
- package/dist/smoke/replay/redact.js +577 -0
- package/dist/smoke/replay/redact.js.map +1 -0
- package/dist/smoke/replay/run.d.ts +119 -0
- package/dist/smoke/replay/run.d.ts.map +1 -0
- package/dist/smoke/replay/run.js +302 -0
- package/dist/smoke/replay/run.js.map +1 -0
- package/dist/team/__tests__/sdk-transport.test.js +334 -6
- package/dist/team/__tests__/sdk-transport.test.js.map +1 -1
- package/dist/team/__tests__/tmux-session.pane-env.test.js +13 -13
- package/dist/team/__tests__/tmux-session.pane-env.test.js.map +1 -1
- package/dist/team/__tests__/tmux-session.spawn.test.js +12 -0
- package/dist/team/__tests__/tmux-session.spawn.test.js.map +1 -1
- package/dist/team/__tests__/tmux-session.split-pane-env.test.js +2 -2
- package/dist/team/__tests__/tmux-session.split-pane-env.test.js.map +1 -1
- package/dist/team/__tests__/worker-launch-ack.test.js +173 -9
- package/dist/team/__tests__/worker-launch-ack.test.js.map +1 -1
- package/dist/team/git-worktree.d.ts.map +1 -1
- package/dist/team/git-worktree.js +2 -1
- package/dist/team/git-worktree.js.map +1 -1
- package/dist/team/model-contract.d.ts.map +1 -1
- package/dist/team/model-contract.js +3 -2
- package/dist/team/model-contract.js.map +1 -1
- package/dist/team/sdk-host.d.ts +44 -0
- package/dist/team/sdk-host.d.ts.map +1 -1
- package/dist/team/sdk-host.js +147 -5
- package/dist/team/sdk-host.js.map +1 -1
- package/dist/team/sdk-policy.d.ts +17 -0
- package/dist/team/sdk-policy.d.ts.map +1 -1
- package/dist/team/sdk-policy.js +79 -1
- package/dist/team/sdk-policy.js.map +1 -1
- package/dist/team/sdk-transport.d.ts +15 -0
- package/dist/team/sdk-transport.d.ts.map +1 -1
- package/dist/team/sdk-transport.js +54 -9
- package/dist/team/sdk-transport.js.map +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +5 -0
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-launch-ack.d.ts +3 -1
- package/dist/team/worker-launch-ack.d.ts.map +1 -1
- package/dist/team/worker-launch-ack.js +73 -8
- package/dist/team/worker-launch-ack.js.map +1 -1
- package/dist/tools/host-smoke-tool.d.ts +5 -1
- package/dist/tools/host-smoke-tool.d.ts.map +1 -1
- package/dist/tools/host-smoke-tool.js +26 -3
- package/dist/tools/host-smoke-tool.js.map +1 -1
- package/dist/workflow/__tests__/alias-resolver.test.js +2 -0
- package/dist/workflow/__tests__/alias-resolver.test.js.map +1 -1
- package/dist/workflow/alias-resolver.js +2 -2
- package/dist/workflow/alias-resolver.js.map +1 -1
- package/docs/CLAUDE.md +3 -2
- package/docs/REFERENCE.md +69 -4
- package/docs/copilot-instructions.md +6 -5
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/scripts/ado-acceptance.mjs +611 -0
- package/scripts/ado-capture.mjs +320 -0
- package/scripts/ado-fixture-import.mjs +293 -0
- package/scripts/keyword-detector.mjs +2 -2
- package/scripts/lib/backlog-to-workitems.mjs +115 -0
- package/scripts/persistent-mode.cjs +1 -1
- package/scripts/persistent-mode.mjs +1 -1
- package/scripts/pre-tool-enforcer.mjs +1 -1
- package/scripts/session-start.mjs +3 -3
- package/scripts/setup-copilot-instructions.sh +1 -1
- package/scripts/spikes/request-handler-probe.mjs +186 -0
- package/skills/autopilot/SKILL.md +3 -3
- package/skills/cancel/SKILL.md +1 -1
- package/skills/ship/SKILL.md +2 -2
- package/skills/team/SKILL.md +3 -3
- package/templates/hooks/keyword-detector.mjs +1 -1
- package/templates/hooks/pre-tool-use.mjs +1 -1
- package/bridge/__pycache__/gyoshu_bridge.cpython-312.pyc +0 -0
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
1
|
+
import { execFileSync, spawn } from 'child_process';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
+
import { PassThrough } from 'stream';
|
|
3
4
|
import { randomUUID } from 'crypto';
|
|
4
5
|
import { existsSync, linkSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync, appendFileSync } from 'fs';
|
|
5
6
|
import { tmpdir } from 'os';
|
|
6
7
|
import { join } from 'path';
|
|
7
8
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
9
|
import { buildSdkExcludedTools, decideSdkPermission } from '../sdk-policy.js';
|
|
9
|
-
import { prependPath, readDoorbell, runSdkHost } from '../sdk-host.js';
|
|
10
|
+
import { prependPath, readDoorbell, readHostCredentials, runSdkHost } from '../sdk-host.js';
|
|
10
11
|
import { ledgerPath, readLedger } from '../../budget/ledger.js';
|
|
11
|
-
import { isSdkTarget, launchSdkHost, readSdkSession, ringDoorbell, sdkPaneId, sdkWorkerFiles, stopSdkHost, } from '../sdk-transport.js';
|
|
12
|
+
import { hostCredentialHandoff, hostSpawnEnv, isSdkTarget, launchSdkHost, readSdkSession, ringDoorbell, sdkPaneId, sdkWorkerFiles, spawnDetachedHost, stopSdkHost, } from '../sdk-transport.js';
|
|
12
13
|
import { awaitWorkerLaunchAcknowledgement, loadWorkerLaunchAttempt, observeWorkerLaunchProvider, prepareWorkerLaunchAttempt, retireAndCleanupCurrentWorkerLaunchAttempt, } from '../worker-launch-ack.js';
|
|
13
14
|
import { teamStateRoot } from '../state-paths.js';
|
|
14
15
|
import { getProcessStartIdentitySync, isProcessAlive } from '../../platform/process-utils.js';
|
|
15
16
|
let TEAM = 'sdk-team';
|
|
16
17
|
const WORKER = 'worker-1';
|
|
18
|
+
/** The Copilot credential every fake host env carries (a worker needs a login or a token). */
|
|
19
|
+
const TEST_TOKEN = 'cgt-test-token';
|
|
17
20
|
let cwd;
|
|
18
21
|
let worktree;
|
|
19
22
|
let pluginRoot;
|
|
@@ -99,6 +102,24 @@ describe('sdk permission policy', () => {
|
|
|
99
102
|
rmSync(outside, { recursive: true, force: true });
|
|
100
103
|
}
|
|
101
104
|
});
|
|
105
|
+
// Each segment is lstat'ed: the reason names the planted link, a dangling one is refused even as the leaf.
|
|
106
|
+
it('names a link segment that resolves outside and refuses a dangling one, and allows a link that stays inside', () => {
|
|
107
|
+
const outside = mkdtempSync(join(tmpdir(), 'sdk-team-outside-'));
|
|
108
|
+
try {
|
|
109
|
+
mkdirSync(join(worktree, 'src', 'real'), { recursive: true });
|
|
110
|
+
symlinkSync(outside, join(worktree, 'src', 'd'), 'junction');
|
|
111
|
+
expect(decideSdkPermission({ kind: 'write', fileName: join(worktree, 'src', 'd', 'config') }, ctx()))
|
|
112
|
+
.toMatchObject({ approve: false, reason: expect.stringMatching(/^write through a link .*src.d that resolves outside/) });
|
|
113
|
+
symlinkSync(join(outside, 'gone'), join(worktree, 'src', 'dangling'), 'junction');
|
|
114
|
+
expect(decideSdkPermission({ kind: 'write', fileName: join(worktree, 'src', 'dangling') }, ctx()))
|
|
115
|
+
.toMatchObject({ approve: false, reason: expect.stringMatching(/dangling link/) });
|
|
116
|
+
symlinkSync(join(worktree, 'src', 'real'), join(worktree, 'src', 'inside'), 'junction');
|
|
117
|
+
expect(decideSdkPermission({ kind: 'write', fileName: join(worktree, 'src', 'inside', 'new.txt') }, ctx()).approve).toBe(true);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
rmSync(outside, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
102
123
|
// `resolve` would collapse `l/../x` to `x`; the kernel climbs from the target of the link `l`.
|
|
103
124
|
it('refuses a read or write path with a .. segment', () => {
|
|
104
125
|
for (const p of [`${worktree}/l/../x.txt`, `${worktree}\\l\\..\\x.txt`, 'l/../x.txt']) {
|
|
@@ -121,6 +142,30 @@ describe('sdk permission policy', () => {
|
|
|
121
142
|
expect(decideSdkPermission({ kind, resolvedPath: clean, path: 'x.txt' }, ctx()).approve).toBe(true);
|
|
122
143
|
}
|
|
123
144
|
});
|
|
145
|
+
// A rewritten `.git` gitfile points the runtime's unsandboxed git at a worker-written config (core.fsmonitor).
|
|
146
|
+
it.each(['win32', 'linux'])('refuses a file-tool write to any .git segment, in every spelling (%s)', (platform) => {
|
|
147
|
+
writeFileSync(join(worktree, '.git'), 'gitdir: /elsewhere\n');
|
|
148
|
+
const c = { ...ctx(), platform };
|
|
149
|
+
for (const fileName of [
|
|
150
|
+
join(worktree, '.git'), '.git', join(worktree, '.GIT', 'config'), join(worktree, 'sub', '.git'), '.git/config',
|
|
151
|
+
`${worktree}\\GIT~1\\x`, `${worktree}/git~12/x`, join(worktree, '.git::$DATA'), join(worktree, 'foo:stream'),
|
|
152
|
+
join(worktree, '.git.'), `${join(worktree, '.git')} `, `${join(worktree, '.git')}. .`, join(worktree, '.git.', 'config'),
|
|
153
|
+
join(stateRoot, '.git', 'config'),
|
|
154
|
+
]) {
|
|
155
|
+
expect(decideSdkPermission({ kind: 'write', fileName }, c), fileName).toMatchObject({ approve: false, reason: expect.stringMatching(/\.git/) });
|
|
156
|
+
}
|
|
157
|
+
for (const fileName of [join(worktree, '.gitignore'), join(worktree, '.github', 'x'), join(worktree, '.gitattributes'), join(worktree, 'src', 'git.ts')]) {
|
|
158
|
+
expect(decideSdkPermission({ kind: 'write', fileName }, c).approve, fileName).toBe(true);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
it('refuses a write that resolves into a .git dir through a planted link', () => {
|
|
162
|
+
mkdirSync(join(worktree, 'sub', '.git'), { recursive: true });
|
|
163
|
+
writeFileSync(join(worktree, 'sub', '.git', 'config'), '');
|
|
164
|
+
symlinkSync(join(worktree, 'sub', '.git'), join(worktree, 'd'), 'junction');
|
|
165
|
+
for (const fileName of [join(worktree, 'd', 'config'), join(worktree, 'd', 'hooks', 'pre-commit')]) {
|
|
166
|
+
expect(decideSdkPermission({ kind: 'write', fileName }, ctx()), fileName).toMatchObject({ approve: false, reason: expect.stringMatching(/\.git/) });
|
|
167
|
+
}
|
|
168
|
+
});
|
|
124
169
|
// A hard link needs no privilege on Windows (NTFS); realpath cannot see it.
|
|
125
170
|
it('refuses a write to a hard-linked or non-regular existing target', () => {
|
|
126
171
|
const outside = mkdtempSync(join(tmpdir(), 'sdk-team-outside-'));
|
|
@@ -193,7 +238,38 @@ describe('sdk permission policy', () => {
|
|
|
193
238
|
['git config --worktree credential.https://github.com.helper x', false],
|
|
194
239
|
['npm test && git-credential-manager get', false],
|
|
195
240
|
['cmd /c git-credential-manager.exe get', false],
|
|
196
|
-
['git credential fill',
|
|
241
|
+
['git credential fill', false],
|
|
242
|
+
['"git" credential fill', false],
|
|
243
|
+
['git -C ../wt credential fill', false],
|
|
244
|
+
['git credential approve', false],
|
|
245
|
+
['GIT credential reject', false],
|
|
246
|
+
['& "C:\\Program Files\\Git\\cmd\\git.exe" credential fill', false],
|
|
247
|
+
['$g="git"; & $g credential fill', false],
|
|
248
|
+
["git cred''ential fill", false],
|
|
249
|
+
['git credential', true],
|
|
250
|
+
// The plain credential reads and the CI checkout's extra header.
|
|
251
|
+
['gh auth token', false],
|
|
252
|
+
['"gh" auth token --hostname github.com', false],
|
|
253
|
+
['& "C:\\Program Files\\GitHub CLI\\gh.exe" auth token', false],
|
|
254
|
+
['gh.exe auth status -t', false],
|
|
255
|
+
['gh auth git-credential get', false],
|
|
256
|
+
["printf 'protocol=https\\nhost=github.com\\n\\n' | gh auth git-credential get", false],
|
|
257
|
+
['git -c credential.helper="!gh auth git-credential" fetch', false],
|
|
258
|
+
["git -c 'credential.https://github.com.helper=!gh auth git-credential' credential fill", false],
|
|
259
|
+
['gh auth setup-git', true],
|
|
260
|
+
['gh auth status --hostname github.com --show-token', false],
|
|
261
|
+
['npm test && gh auth token', false],
|
|
262
|
+
['az account get-access-token', false],
|
|
263
|
+
['az.cmd account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798', false],
|
|
264
|
+
['"az" account get-access-token', false],
|
|
265
|
+
['git config --get http.https://github.com/.extraheader', false],
|
|
266
|
+
['git config --get-regexp extraheader', false],
|
|
267
|
+
['git config --list --show-origin | findstr extraheader', true],
|
|
268
|
+
['gh auth status', true],
|
|
269
|
+
['gh pr view 12', true],
|
|
270
|
+
['az account show', true],
|
|
271
|
+
['rg "gh auth token" docs', true],
|
|
272
|
+
['git commit -m "credential fill docs"', true],
|
|
197
273
|
['rg git-credential-manager src', true],
|
|
198
274
|
['cat docs/git-credential-notes.md', true],
|
|
199
275
|
['git -c user.name=x commit -m y', true],
|
|
@@ -373,7 +449,7 @@ function deps(sdk, over = {}) {
|
|
|
373
449
|
// The terminal record's shape follows the real platform, which the shared observers read.
|
|
374
450
|
platform: process.platform,
|
|
375
451
|
pollMs: 10,
|
|
376
|
-
env: { [process.platform === 'win32' ? 'Path' : 'PATH']: '/usr/bin', OMC_STRIPPED: '1', COPILOT_HOME: '/real-home' },
|
|
452
|
+
env: { [process.platform === 'win32' ? 'Path' : 'PATH']: '/usr/bin', OMC_STRIPPED: '1', COPILOT_HOME: '/real-home', COPILOT_GITHUB_TOKEN: TEST_TOKEN },
|
|
377
453
|
...over,
|
|
378
454
|
};
|
|
379
455
|
}
|
|
@@ -424,6 +500,8 @@ describe('sdk host', () => {
|
|
|
424
500
|
expect(cfg.disabledMcpServers).toEqual(['github-mcp-server']);
|
|
425
501
|
expect(cfg.excludedTools).toEqual(expect.arrayContaining(['t-host_smoke', 'task', 'web_fetch']));
|
|
426
502
|
expect(cfg.model).toBe('gpt-test');
|
|
503
|
+
// The Copilot credential goes over the session RPC, not into the env shell children inherit.
|
|
504
|
+
expect(cfg.gitHubToken).toBe(TEST_TOKEN);
|
|
427
505
|
// Runtime: installed exe, credit cap floor, deny flag, no allow-all, worker env, isolated home.
|
|
428
506
|
expect(rec.connection?.path).toBe('C:/fake/copilot.exe');
|
|
429
507
|
expect(rec.connection?.args).toEqual(['--log-level', 'debug', '--max-ai-credits', '30', '--deny-tool=web_fetch']);
|
|
@@ -433,6 +511,7 @@ describe('sdk host', () => {
|
|
|
433
511
|
expect(env.OMC_TEAM_WORKER).toBe(`${TEAM}/${WORKER}`);
|
|
434
512
|
expect(env.OMC_STRIPPED).toBeUndefined();
|
|
435
513
|
expect(env.COPILOT_HOME).toBe(sdkWorkerFiles(stateRoot, WORKER).home);
|
|
514
|
+
expect(env.COPILOT_GITHUB_TOKEN).toBeUndefined();
|
|
436
515
|
const pathKey = Object.keys(env).find((k) => k.toUpperCase() === 'PATH');
|
|
437
516
|
expect(env[pathKey]?.startsWith(sdkWorkerFiles(stateRoot, WORKER).bin)).toBe(true);
|
|
438
517
|
expect(existsSync(join(sdkWorkerFiles(stateRoot, WORKER).bin, 'omg.cmd'))).toBe(true);
|
|
@@ -474,6 +553,8 @@ describe('sdk host', () => {
|
|
|
474
553
|
const toolNames = (config) => (config.tools ?? []).map((t) => t.name);
|
|
475
554
|
async function runWith(builder, hostEnv, opts = {}) {
|
|
476
555
|
const attempt = await newAttempt();
|
|
556
|
+
// In place: a test compares the caller's object with the runtime env after adoption.
|
|
557
|
+
hostEnv.COPILOT_GITHUB_TOKEN ??= TEST_TOKEN;
|
|
477
558
|
const { loaded, rec } = fakeSdk(opts.fake);
|
|
478
559
|
const calls = [];
|
|
479
560
|
const cleanups = [];
|
|
@@ -497,7 +578,7 @@ describe('sdk host', () => {
|
|
|
497
578
|
}
|
|
498
579
|
const withTools = (tools = [fakeTool]) => (async () => () => ({ tools, disabledMcpServer: 't', cleanup: async () => { } }));
|
|
499
580
|
it('registers the tools, disables the t server and gives the handlers the session env', async () => {
|
|
500
|
-
const hostEnv = { [process.platform === 'win32' ? 'Path' : 'PATH']: '/usr/bin', OMC_STRIPPED: '1', COPILOT_HOME: '/real-home' };
|
|
581
|
+
const hostEnv = { [process.platform === 'win32' ? 'Path' : 'PATH']: '/usr/bin', OMC_STRIPPED: '1', COPILOT_HOME: '/real-home', AWS_SECRET_ACCESS_KEY: 'aws' };
|
|
501
582
|
const { cfg, connEnv, calls, cleanups, events, session } = await runWith(withTools(), hostEnv);
|
|
502
583
|
expect(cfg.tools).toEqual([fakeTool]);
|
|
503
584
|
expect(cfg.disabledMcpServers).toEqual(['github-mcp-server', 't']);
|
|
@@ -511,6 +592,10 @@ describe('sdk host', () => {
|
|
|
511
592
|
// The host env now equals the runtime's (MCP child) env.
|
|
512
593
|
expect(hostEnv).toEqual(connEnv);
|
|
513
594
|
expect(hostEnv.OMC_STRIPPED).toBeUndefined();
|
|
595
|
+
// The in-process handlers get the scrubbed env too.
|
|
596
|
+
expect(hostEnv.AWS_SECRET_ACCESS_KEY).toBeUndefined();
|
|
597
|
+
expect(hostEnv.COPILOT_GITHUB_TOKEN).toBeUndefined();
|
|
598
|
+
expect(cfg.gitHubToken).toBe(TEST_TOKEN);
|
|
514
599
|
expect(hostEnv.COPILOT_HOME).toBe(sdkWorkerFiles(stateRoot, WORKER).home);
|
|
515
600
|
// Teardown ran the tools' cleanup once and removed every process guard.
|
|
516
601
|
expect(cleanups).toHaveLength(1);
|
|
@@ -629,6 +714,137 @@ describe('sdk host', () => {
|
|
|
629
714
|
expect(session.last_error).toMatch(/credit cap 10 reached/);
|
|
630
715
|
expect(session.aborts).toBeGreaterThanOrEqual(2);
|
|
631
716
|
});
|
|
717
|
+
describe('worker env', () => {
|
|
718
|
+
const pathKey = process.platform === 'win32' ? 'Path' : 'PATH';
|
|
719
|
+
async function runEnv(hostEnv, specOver = {}) {
|
|
720
|
+
const attempt = await newAttempt();
|
|
721
|
+
const { loaded, rec } = fakeSdk();
|
|
722
|
+
const host = await hostWithLeader(attempt, deps(loaded, { env: hostEnv }), async () => {
|
|
723
|
+
await until(() => readSdkSession(stateRoot, WORKER)?.state === 'idle');
|
|
724
|
+
ringDoorbell(stateRoot, WORKER, { kind: 'shutdown' });
|
|
725
|
+
}, specFor(attempt, specOver));
|
|
726
|
+
expect(await host).toBe('stopped');
|
|
727
|
+
return { env: rec.connection.env, cfg: rec.sessions[0] };
|
|
728
|
+
}
|
|
729
|
+
const secrets = {
|
|
730
|
+
AWS_ACCESS_KEY_ID: 'a', AWS_SECRET_ACCESS_KEY: 'b', AWS_SESSION_TOKEN: 'c',
|
|
731
|
+
AZURE_CLIENT_SECRET: 'd', AZURE_DEVOPS_EXT_PAT: 'e', ARM_CLIENT_SECRET: 'f',
|
|
732
|
+
NPM_TOKEN: 'g', ANTHROPIC_API_KEY: 'h', OPENAI_API_KEY: 'i', SSH_AUTH_SOCK: '/tmp/agent',
|
|
733
|
+
GIT_ASKPASS: '/askpass', GIT_SSH_COMMAND: 'ssh -i key', GH_TOKEN: 'gh', GITHUB_TOKEN: 'ghub',
|
|
734
|
+
GCM_CREDENTIAL_STORE: 'wincredman', GIT_CONFIG_GLOBAL: '/evil', GIT_CONFIG_PARAMETERS: "'credential.helper=x'",
|
|
735
|
+
SYSTEM_ACCESSTOKEN: 'ado',
|
|
736
|
+
};
|
|
737
|
+
const kept = {
|
|
738
|
+
JAVA_HOME: '/jdk', HTTPS_PROXY: 'http://proxy:8080', NO_PROXY: 'localhost', NODE_EXTRA_CA_CERTS: '/ca.pem',
|
|
739
|
+
APPDATA: '/appdata', LOCALAPPDATA: '/localappdata', USERPROFILE: '/user', HOME: '/user', TEMP: '/tmp',
|
|
740
|
+
SystemRoot: 'C:\\Windows', ANDROID_HOME: '/sdk',
|
|
741
|
+
};
|
|
742
|
+
it('drops every credential, keeps toolchain, proxy and home vars, and resets the credential helper', async () => {
|
|
743
|
+
const { env, cfg } = await runEnv({ [pathKey]: '/usr/bin', COPILOT_GITHUB_TOKEN: TEST_TOKEN, ...secrets, ...kept });
|
|
744
|
+
for (const key of [...Object.keys(secrets), 'COPILOT_GITHUB_TOKEN'])
|
|
745
|
+
expect(env[key], key).toBeUndefined();
|
|
746
|
+
expect(env).toMatchObject(kept);
|
|
747
|
+
const gitConfig = Object.fromEntries(Object.entries(env).filter(([k]) => k.toUpperCase().startsWith('GIT_CONFIG')));
|
|
748
|
+
// The temp worktree is no repository: no URL-scoped extra header to reset.
|
|
749
|
+
expect(gitConfig).toEqual({
|
|
750
|
+
GIT_CONFIG_COUNT: '3',
|
|
751
|
+
GIT_CONFIG_KEY_0: 'credential.helper', GIT_CONFIG_VALUE_0: '',
|
|
752
|
+
GIT_CONFIG_KEY_1: 'http.extraHeader', GIT_CONFIG_VALUE_1: '',
|
|
753
|
+
GIT_CONFIG_KEY_2: 'core.sshCommand', GIT_CONFIG_VALUE_2: 'ssh -o IdentityAgent=none -o IdentitiesOnly=yes -o BatchMode=yes',
|
|
754
|
+
});
|
|
755
|
+
const emptyDir = join(sdkWorkerFiles(stateRoot, WORKER).home, 'no-credentials');
|
|
756
|
+
expect(env).toMatchObject({ GH_CONFIG_DIR: emptyDir, AZURE_CONFIG_DIR: emptyDir, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never' });
|
|
757
|
+
expect(existsSync(emptyDir)).toBe(true);
|
|
758
|
+
expect(env.OMC_TEAM_WORKER).toBe(`${TEAM}/${WORKER}`);
|
|
759
|
+
expect(cfg.gitHubToken).toBe(TEST_TOKEN);
|
|
760
|
+
});
|
|
761
|
+
it('drops credentials worker_env carries, and the leader COPILOT_HOME / COPILOT_MODEL do not override the worker', async () => {
|
|
762
|
+
const attemptEnv = { OMC_TEAM_WORKER: `${TEAM}/${WORKER}` };
|
|
763
|
+
const { env } = await runEnv({ [pathKey]: '/usr/bin', COPILOT_GITHUB_TOKEN: TEST_TOKEN }, {
|
|
764
|
+
worker_env: { ...attemptEnv, NPM_TOKEN: 'npm', GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'alias.p', GIT_CONFIG_VALUE_0: 'push',
|
|
765
|
+
COPILOT_HOME: '/leader-home', COPILOT_MODEL: 'leader-model', OMC_STATE_DIR: omcStateDir },
|
|
766
|
+
});
|
|
767
|
+
expect(env.NPM_TOKEN).toBeUndefined();
|
|
768
|
+
expect(env.GIT_CONFIG_KEY_0).toBe('credential.helper');
|
|
769
|
+
expect(env.COPILOT_HOME).toBe(sdkWorkerFiles(stateRoot, WORKER).home);
|
|
770
|
+
expect(env.COPILOT_MODEL).toBeUndefined();
|
|
771
|
+
expect(env.OMC_STATE_DIR).toBe(omcStateDir);
|
|
772
|
+
});
|
|
773
|
+
it('without a stored login GH_TOKEN becomes the session credential', async () => {
|
|
774
|
+
const { env, cfg } = await runEnv({ [pathKey]: '/usr/bin', GH_TOKEN: 'gh-only' });
|
|
775
|
+
expect(cfg.gitHubToken).toBe('gh-only');
|
|
776
|
+
expect(env.GH_TOKEN).toBeUndefined();
|
|
777
|
+
});
|
|
778
|
+
it('with a stored login no generic token is sent and none is needed', async () => {
|
|
779
|
+
const userConfig = join(cwd, 'user-config');
|
|
780
|
+
mkdirSync(userConfig, { recursive: true });
|
|
781
|
+
writeFileSync(join(userConfig, 'config.json'), JSON.stringify({ loggedInUsers: [{ login: 'robin' }], lastLoggedInUser: { login: 'robin' } }));
|
|
782
|
+
const { cfg } = await runEnv({ [pathKey]: '/usr/bin', GH_TOKEN: 'gh' }, { user_config_dir: userConfig });
|
|
783
|
+
expect(cfg.gitHubToken).toBeUndefined();
|
|
784
|
+
});
|
|
785
|
+
// A CI checkout (actions/checkout persist-credentials, Azure Pipelines) writes the job token as a URL-scoped
|
|
786
|
+
// extra header into .git/config; the plain `http.extraHeader=` reset does not clear a URL-scoped one.
|
|
787
|
+
it('resets every URL-scoped http extra header the worktree config holds, so git sends none', async () => {
|
|
788
|
+
const git = (args, env = process.env) => execFileSync('git', args, { cwd: worktree, env, encoding: 'utf8' });
|
|
789
|
+
git(['init', '-q']);
|
|
790
|
+
git(['config', 'http.https://github.com/.extraheader', 'AUTHORIZATION: basic c2VjcmV0']);
|
|
791
|
+
git(['config', 'http.https://dev.azure.com/org/.extraHeader', 'AUTHORIZATION: bearer secret']);
|
|
792
|
+
git(['config', 'http.extraheader', 'AUTHORIZATION: basic plain']);
|
|
793
|
+
const { env } = await runEnv({ [pathKey]: process.env[pathKey] ?? process.env.PATH, COPILOT_GITHUB_TOKEN: TEST_TOKEN, SystemRoot: process.env.SystemRoot });
|
|
794
|
+
const keys = Array.from({ length: Number(env.GIT_CONFIG_COUNT) }, (_, i) => [env[`GIT_CONFIG_KEY_${i}`], env[`GIT_CONFIG_VALUE_${i}`]]);
|
|
795
|
+
expect(keys).toEqual(expect.arrayContaining([
|
|
796
|
+
['http.https://github.com/.extraheader', ''],
|
|
797
|
+
['http.https://dev.azure.com/org/.extraheader', ''],
|
|
798
|
+
['http.extraHeader', ''],
|
|
799
|
+
]));
|
|
800
|
+
expect(keys).toHaveLength(5);
|
|
801
|
+
const runEnvGit = { ...process.env, ...env };
|
|
802
|
+
for (const url of ['https://github.com/o/r', 'https://dev.azure.com/org/p/_git/r', 'https://example.com/x']) {
|
|
803
|
+
let headers = '';
|
|
804
|
+
try {
|
|
805
|
+
headers = git(['config', '--get-urlmatch', 'http.extraheader', url], runEnvGit).trim();
|
|
806
|
+
}
|
|
807
|
+
catch { /* exit 1: none */ }
|
|
808
|
+
expect(headers, url).toBe('');
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
it('takes the Copilot credential from the stdin handoff when the host env has none', async () => {
|
|
812
|
+
const attempt = await newAttempt();
|
|
813
|
+
const { loaded, rec } = fakeSdk();
|
|
814
|
+
const host = await hostWithLeader(attempt, deps(loaded, { env: { [pathKey]: '/usr/bin' }, credentials: { COPILOT_GITHUB_TOKEN: 'from-stdin' } }), async () => {
|
|
815
|
+
await until(() => readSdkSession(stateRoot, WORKER)?.state === 'idle');
|
|
816
|
+
ringDoorbell(stateRoot, WORKER, { kind: 'shutdown' });
|
|
817
|
+
});
|
|
818
|
+
expect(await host).toBe('stopped');
|
|
819
|
+
expect(rec.sessions[0]?.gitHubToken).toBe('from-stdin');
|
|
820
|
+
expect(Object.values(rec.connection.env)).not.toContain('from-stdin');
|
|
821
|
+
});
|
|
822
|
+
it('no stored login and no token fails the start before the runtime is spawned', async () => {
|
|
823
|
+
const attempt = await newAttempt();
|
|
824
|
+
const { loaded, rec } = fakeSdk();
|
|
825
|
+
const host = await hostWithLeader(attempt, deps(loaded, { env: { [pathKey]: '/usr/bin', NPM_TOKEN: 'x' } }), async () => { });
|
|
826
|
+
expect(await host).toBe('start_failed');
|
|
827
|
+
expect(rec.ops).toEqual([]);
|
|
828
|
+
expect(readSdkSession(stateRoot, WORKER)?.last_error).toMatch(/stored Copilot login .* or COPILOT_GITHUB_TOKEN/);
|
|
829
|
+
expect(await observeWorkerLaunchProvider(attempt)).toBe('dead');
|
|
830
|
+
});
|
|
831
|
+
it('the login requirement is skipped for a replay SDK (its marker), not for the replay env alone', async () => {
|
|
832
|
+
const replayEnv = { [pathKey]: '/usr/bin', OMG_COPILOT_CASSETTE_MODE: 'replay' };
|
|
833
|
+
const refused = await newAttempt();
|
|
834
|
+
const plain = fakeSdk();
|
|
835
|
+
const refusedHost = await hostWithLeader(refused, deps(plain.loaded, { env: replayEnv }), async () => { });
|
|
836
|
+
expect(await refusedHost).toBe('start_failed');
|
|
837
|
+
expect(plain.rec.ops).toEqual([]);
|
|
838
|
+
const attempt = await newAttempt();
|
|
839
|
+
const { loaded, rec } = fakeSdk();
|
|
840
|
+
const host = await hostWithLeader(attempt, deps({ ...loaded, cassette: 'replay' }, { env: { [pathKey]: '/usr/bin' } }), async () => {
|
|
841
|
+
await until(() => readSdkSession(stateRoot, WORKER)?.state === 'idle');
|
|
842
|
+
ringDoorbell(stateRoot, WORKER, { kind: 'shutdown' });
|
|
843
|
+
});
|
|
844
|
+
expect(await host).toBe('stopped');
|
|
845
|
+
expect(rec.sessions[0]?.gitHubToken).toBeUndefined();
|
|
846
|
+
});
|
|
847
|
+
});
|
|
632
848
|
it('a missing SDK fails the launch with a terminal record and an install hint', async () => {
|
|
633
849
|
const attempt = await newAttempt();
|
|
634
850
|
const host = await hostWithLeader(attempt, deps(null), async () => { });
|
|
@@ -824,6 +1040,60 @@ describe('launchSdkHost', () => {
|
|
|
824
1040
|
expect(rec.ops).toEqual([]);
|
|
825
1041
|
await until(() => !isProcessAlive(host.pid));
|
|
826
1042
|
});
|
|
1043
|
+
it('stops waiting as soon as a host fails after provider_started', async () => {
|
|
1044
|
+
const host = await dummyProcess();
|
|
1045
|
+
let run;
|
|
1046
|
+
const t0 = Date.now();
|
|
1047
|
+
const result = await launchSdkHost(launchInput({
|
|
1048
|
+
ackTimeoutMs: 20_000,
|
|
1049
|
+
spawnHost: (_cli, specPath) => {
|
|
1050
|
+
// A real host without the SDK publishes provider_started, then its terminal record and `failed` session.
|
|
1051
|
+
run = runSdkHost(specAt(specPath), deps(null));
|
|
1052
|
+
return host.pid;
|
|
1053
|
+
},
|
|
1054
|
+
}));
|
|
1055
|
+
expect(await run).toBe('sdk_missing');
|
|
1056
|
+
expect(existsSync(result.attempt.startedPath)).toBe(true);
|
|
1057
|
+
expect(result).toMatchObject({ ok: false, reason: expect.stringMatching(/^sdk_host_failed_at_start:@github\/copilot-sdk is not installed/) });
|
|
1058
|
+
expect(Date.now() - t0).toBeLessThan(4_000);
|
|
1059
|
+
await until(() => !isProcessAlive(host.pid));
|
|
1060
|
+
});
|
|
1061
|
+
/** Ack like a host, then run `afterAccept` once the leader has accepted. */
|
|
1062
|
+
function ackingHost(pid, afterAccept) {
|
|
1063
|
+
return (_cli, specPath) => {
|
|
1064
|
+
void attemptFor(specAt(specPath)).then(async (a) => {
|
|
1065
|
+
writeFileSync(a.ackPath, JSON.stringify({
|
|
1066
|
+
schema_version: a.schema_version, attempt_id: a.attempt_id, nonce: a.nonce, instance_id: a.instance_id,
|
|
1067
|
+
team_name: a.team_name, worker_name: a.worker_name, pane_id: a.pane_id, provider: a.provider,
|
|
1068
|
+
created_at: a.created_at, kind: 'worker_launch_ack', written_at: new Date().toISOString(),
|
|
1069
|
+
}));
|
|
1070
|
+
await until(() => existsSync(a.decisionPath));
|
|
1071
|
+
afterAccept(a);
|
|
1072
|
+
});
|
|
1073
|
+
return pid;
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
it('stops waiting as soon as the attempt is retired', async () => {
|
|
1077
|
+
const host = await dummyProcess();
|
|
1078
|
+
const t0 = Date.now();
|
|
1079
|
+
const result = await launchSdkHost(launchInput({
|
|
1080
|
+
ackTimeoutMs: 20_000,
|
|
1081
|
+
spawnHost: ackingHost(host.pid, (a) => writeFileSync(`${a.decisionPath}.retired`, '{}')),
|
|
1082
|
+
}));
|
|
1083
|
+
expect(result).toMatchObject({ ok: false, reason: 'sdk_host_failed_before_start:unknown', hostPid: host.pid });
|
|
1084
|
+
expect(Date.now() - t0).toBeLessThan(5_000);
|
|
1085
|
+
await until(() => !isProcessAlive(host.pid));
|
|
1086
|
+
});
|
|
1087
|
+
it('stops waiting as soon as the host process dies', async () => {
|
|
1088
|
+
const host = await dummyProcess();
|
|
1089
|
+
const t0 = Date.now();
|
|
1090
|
+
const result = await launchSdkHost(launchInput({
|
|
1091
|
+
ackTimeoutMs: 20_000,
|
|
1092
|
+
spawnHost: ackingHost(host.pid, () => { process.kill(host.pid, 'SIGKILL'); }),
|
|
1093
|
+
}));
|
|
1094
|
+
expect(result).toMatchObject({ ok: false, reason: 'sdk_host_failed_before_start:unknown', hostPid: host.pid });
|
|
1095
|
+
expect(Date.now() - t0).toBeLessThan(5_000);
|
|
1096
|
+
});
|
|
827
1097
|
});
|
|
828
1098
|
describe('stopSdkHost', () => {
|
|
829
1099
|
it('rings stop and returns once the host reports its provider dead', async () => {
|
|
@@ -895,4 +1165,62 @@ describe('stopSdkHost', () => {
|
|
|
895
1165
|
expect(isProcessAlive(orphan.pid)).toBe(true); // unverifiable pids are reported, not killed
|
|
896
1166
|
}, 20_000);
|
|
897
1167
|
});
|
|
1168
|
+
describe('host credential handoff', () => {
|
|
1169
|
+
it('spawns the detached host with a credential-free env and hands the Copilot tokens over stdin', async () => {
|
|
1170
|
+
const dir = mkdtempSync(join(tmpdir(), 'sdk-host-handoff-'));
|
|
1171
|
+
try {
|
|
1172
|
+
// Stands in for cli.cjs: records its env and stdin at the --spec path.
|
|
1173
|
+
const fakeCli = join(dir, 'fake-cli.cjs');
|
|
1174
|
+
writeFileSync(fakeCli, [
|
|
1175
|
+
"const fs = require('fs');",
|
|
1176
|
+
"let input = '';",
|
|
1177
|
+
"process.stdin.on('data', (c) => { input += c; });",
|
|
1178
|
+
"process.stdin.on('end', () => { fs.writeFileSync(process.argv[5], JSON.stringify({ env: process.env, input })); });",
|
|
1179
|
+
].join('\n'));
|
|
1180
|
+
const out = join(dir, 'out.json');
|
|
1181
|
+
const leaderEnv = {
|
|
1182
|
+
...process.env,
|
|
1183
|
+
COPILOT_GITHUB_TOKEN: 'cgt', GH_TOKEN: 'gh', AWS_SECRET_ACCESS_KEY: 'aws', GIT_CONFIG_COUNT: '1',
|
|
1184
|
+
OMC_STATE_DIR: omcStateDir, OMG_TEST_FLAG: '1',
|
|
1185
|
+
};
|
|
1186
|
+
const pid = spawnDetachedHost(fakeCli, out, join(dir, 'host.log'), dir, leaderEnv);
|
|
1187
|
+
expect(pid).toBeGreaterThan(0);
|
|
1188
|
+
await until(() => existsSync(out), 15_000);
|
|
1189
|
+
const seen = JSON.parse(readFileSync(out, 'utf8'));
|
|
1190
|
+
const upperKeys = Object.keys(seen.env).map((k) => k.toUpperCase());
|
|
1191
|
+
for (const key of ['COPILOT_GITHUB_TOKEN', 'GH_TOKEN', 'AWS_SECRET_ACCESS_KEY', 'GIT_CONFIG_COUNT'])
|
|
1192
|
+
expect(upperKeys, key).not.toContain(key);
|
|
1193
|
+
expect(seen.env.OMC_STATE_DIR).toBe(omcStateDir);
|
|
1194
|
+
expect(seen.env.OMG_TEST_FLAG).toBe('1');
|
|
1195
|
+
expect(JSON.parse(seen.input)).toEqual({ COPILOT_GITHUB_TOKEN: 'cgt', GH_TOKEN: 'gh' });
|
|
1196
|
+
}
|
|
1197
|
+
finally {
|
|
1198
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1199
|
+
}
|
|
1200
|
+
}, 20_000);
|
|
1201
|
+
it('hostCredentialHandoff hands over the Copilot tokens, and none in a cassette replay', () => {
|
|
1202
|
+
const env = { PATH: '/bin', COPILOT_GITHUB_TOKEN: 'c', GH_TOKEN: 'g', NPM_TOKEN: 'n' };
|
|
1203
|
+
expect(JSON.parse(hostCredentialHandoff(env))).toEqual({ COPILOT_GITHUB_TOKEN: 'c', GH_TOKEN: 'g' });
|
|
1204
|
+
expect(hostCredentialHandoff({ ...env, OMG_COPILOT_CASSETTE_MODE: 'replay' })).toBe('{}\n');
|
|
1205
|
+
expect(JSON.parse(hostCredentialHandoff({ ...env, OMG_COPILOT_CASSETTE_MODE: 'record' }))).toEqual({ COPILOT_GITHUB_TOKEN: 'c', GH_TOKEN: 'g' });
|
|
1206
|
+
});
|
|
1207
|
+
it('hostSpawnEnv drops credentials and keeps the rest', () => {
|
|
1208
|
+
expect(hostSpawnEnv({ PATH: '/bin', OMC_X: '1', github_token: 't', NPM_TOKEN: 'n', JAVA_HOME: '/jdk' })).toEqual({ PATH: '/bin', OMC_X: '1', JAVA_HOME: '/jdk' });
|
|
1209
|
+
});
|
|
1210
|
+
it('reads the handoff once: only the known token names, nothing on bad input, a TTY or a timeout', async () => {
|
|
1211
|
+
const feed = async (text, timeoutMs = 1_000) => {
|
|
1212
|
+
const stream = new PassThrough();
|
|
1213
|
+
const read = readHostCredentials(stream, timeoutMs);
|
|
1214
|
+
if (text !== null)
|
|
1215
|
+
stream.end(text);
|
|
1216
|
+
return read;
|
|
1217
|
+
};
|
|
1218
|
+
expect(await feed('{"COPILOT_GITHUB_TOKEN":"c","GITHUB_TOKEN":"g","AWS_SECRET_ACCESS_KEY":"x","GH_TOKEN":7}\n')).toEqual({ COPILOT_GITHUB_TOKEN: 'c', GITHUB_TOKEN: 'g' });
|
|
1219
|
+
expect(await feed('')).toEqual({});
|
|
1220
|
+
expect(await feed('not json')).toEqual({});
|
|
1221
|
+
expect(await feed(null, 50)).toEqual({});
|
|
1222
|
+
const tty = Object.assign(new PassThrough(), { isTTY: true });
|
|
1223
|
+
expect(await readHostCredentials(tty, 1_000)).toEqual({});
|
|
1224
|
+
});
|
|
1225
|
+
});
|
|
898
1226
|
//# sourceMappingURL=sdk-transport.test.js.map
|