@agentic-sdlc-kit/cli 0.0.0-stage → 0.9.1
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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/application/agent/execution-store.d.ts +55 -0
- package/dist/application/agent/execution-store.d.ts.map +1 -0
- package/dist/application/agent/execution-store.js +91 -0
- package/dist/application/agent/execution-store.js.map +1 -0
- package/dist/application/agent/gateway.d.ts +74 -0
- package/dist/application/agent/gateway.d.ts.map +1 -0
- package/dist/application/agent/gateway.js +580 -0
- package/dist/application/agent/gateway.js.map +1 -0
- package/dist/application/agent/index.d.ts +6 -0
- package/dist/application/agent/index.d.ts.map +1 -0
- package/dist/application/agent/index.js +18 -0
- package/dist/application/agent/index.js.map +1 -0
- package/dist/application/agent/orchestrator.d.ts +76 -0
- package/dist/application/agent/orchestrator.d.ts.map +1 -0
- package/dist/application/agent/orchestrator.js +422 -0
- package/dist/application/agent/orchestrator.js.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
- package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
- package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/index.js +13 -0
- package/dist/application/agent/providers/claude-code/index.js.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
- package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.js +577 -0
- package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
- package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
- package/dist/application/agent/test-fixture.d.ts +15 -0
- package/dist/application/agent/test-fixture.d.ts.map +1 -0
- package/dist/application/agent/test-fixture.js +93 -0
- package/dist/application/agent/test-fixture.js.map +1 -0
- package/dist/application/agent/workspace.d.ts +24 -0
- package/dist/application/agent/workspace.d.ts.map +1 -0
- package/dist/application/agent/workspace.js +139 -0
- package/dist/application/agent/workspace.js.map +1 -0
- package/dist/application/dispatcher.d.ts +13 -0
- package/dist/application/dispatcher.d.ts.map +1 -0
- package/dist/application/dispatcher.js +116 -0
- package/dist/application/dispatcher.js.map +1 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +6 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/registry.d.ts +8 -0
- package/dist/application/registry.d.ts.map +1 -0
- package/dist/application/registry.js +17 -0
- package/dist/application/registry.js.map +1 -0
- package/dist/application/version.d.ts +2 -0
- package/dist/application/version.d.ts.map +1 -0
- package/dist/application/version.js +7 -0
- package/dist/application/version.js.map +1 -0
- package/dist/commands/attach-exclude.d.ts +8 -0
- package/dist/commands/attach-exclude.d.ts.map +1 -0
- package/dist/commands/attach-exclude.js +48 -0
- package/dist/commands/attach-exclude.js.map +1 -0
- package/dist/commands/attach-git.d.ts +11 -0
- package/dist/commands/attach-git.d.ts.map +1 -0
- package/dist/commands/attach-git.js +40 -0
- package/dist/commands/attach-git.js.map +1 -0
- package/dist/commands/attach-store.d.ts +10 -0
- package/dist/commands/attach-store.d.ts.map +1 -0
- package/dist/commands/attach-store.js +107 -0
- package/dist/commands/attach-store.js.map +1 -0
- package/dist/commands/attach.d.ts +8 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +124 -0
- package/dist/commands/attach.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/elicit.d.ts +3 -0
- package/dist/commands/elicit.d.ts.map +1 -0
- package/dist/commands/elicit.js +163 -0
- package/dist/commands/elicit.js.map +1 -0
- package/dist/commands/evolve.d.ts +3 -0
- package/dist/commands/evolve.d.ts.map +1 -0
- package/dist/commands/evolve.js +165 -0
- package/dist/commands/evolve.js.map +1 -0
- package/dist/commands/feature.d.ts +13 -0
- package/dist/commands/feature.d.ts.map +1 -0
- package/dist/commands/feature.js +326 -0
- package/dist/commands/feature.js.map +1 -0
- package/dist/commands/fix.d.ts +4 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +53 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/help.d.ts +4 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +32 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/host-apply.d.ts +12 -0
- package/dist/commands/host-apply.d.ts.map +1 -0
- package/dist/commands/host-apply.js +43 -0
- package/dist/commands/host-apply.js.map +1 -0
- package/dist/commands/host.d.ts +3 -0
- package/dist/commands/host.d.ts.map +1 -0
- package/dist/commands/host.js +107 -0
- package/dist/commands/host.js.map +1 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +26 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +92 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/inspect.d.ts +3 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +64 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/install.d.ts +3 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +337 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/journal.d.ts +3 -0
- package/dist/commands/journal.d.ts.map +1 -0
- package/dist/commands/journal.js +107 -0
- package/dist/commands/journal.js.map +1 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +85 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +68 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/next.d.ts +3 -0
- package/dist/commands/next.d.ts.map +1 -0
- package/dist/commands/next.js +107 -0
- package/dist/commands/next.js.map +1 -0
- package/dist/commands/optimize.d.ts +3 -0
- package/dist/commands/optimize.d.ts.map +1 -0
- package/dist/commands/optimize.js +28 -0
- package/dist/commands/optimize.js.map +1 -0
- package/dist/commands/plugin-linker.d.ts +43 -0
- package/dist/commands/plugin-linker.d.ts.map +1 -0
- package/dist/commands/plugin-linker.js +216 -0
- package/dist/commands/plugin-linker.js.map +1 -0
- package/dist/commands/refactor.d.ts +3 -0
- package/dist/commands/refactor.d.ts.map +1 -0
- package/dist/commands/refactor.js +32 -0
- package/dist/commands/refactor.js.map +1 -0
- package/dist/commands/skills-install-commit.d.ts +34 -0
- package/dist/commands/skills-install-commit.d.ts.map +1 -0
- package/dist/commands/skills-install-commit.js +113 -0
- package/dist/commands/skills-install-commit.js.map +1 -0
- package/dist/commands/skills-install-manifest.d.ts +35 -0
- package/dist/commands/skills-install-manifest.d.ts.map +1 -0
- package/dist/commands/skills-install-manifest.js +89 -0
- package/dist/commands/skills-install-manifest.js.map +1 -0
- package/dist/commands/skills-install-report.d.ts +12 -0
- package/dist/commands/skills-install-report.d.ts.map +1 -0
- package/dist/commands/skills-install-report.js +44 -0
- package/dist/commands/skills-install-report.js.map +1 -0
- package/dist/commands/skills-install-secure.d.ts +14 -0
- package/dist/commands/skills-install-secure.d.ts.map +1 -0
- package/dist/commands/skills-install-secure.js +96 -0
- package/dist/commands/skills-install-secure.js.map +1 -0
- package/dist/commands/skills-install.d.ts +15 -0
- package/dist/commands/skills-install.d.ts.map +1 -0
- package/dist/commands/skills-install.js +182 -0
- package/dist/commands/skills-install.js.map +1 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +217 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/types.d.ts +19 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/uninstall.d.ts +3 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +113 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/commands/validate-plan.d.ts +3 -0
- package/dist/commands/validate-plan.d.ts.map +1 -0
- package/dist/commands/validate-plan.js +62 -0
- package/dist/commands/validate-plan.js.map +1 -0
- package/dist/commands/validate-spec.d.ts +3 -0
- package/dist/commands/validate-spec.d.ts.map +1 -0
- package/dist/commands/validate-spec.js +62 -0
- package/dist/commands/validate-spec.js.map +1 -0
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +103 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +12 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +2 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +10 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/index.d.ts +2 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +3 -0
- package/dist/output/index.js.map +1 -0
- package/package.json +37 -3
- package/src/application/agent/execution-store.ts +163 -0
- package/src/application/agent/gateway.test.ts +529 -0
- package/src/application/agent/gateway.ts +744 -0
- package/src/application/agent/index.ts +18 -0
- package/src/application/agent/orchestrator.test.ts +341 -0
- package/src/application/agent/orchestrator.ts +629 -0
- package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
- package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
- package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
- package/src/application/agent/providers/claude-code/index.ts +28 -0
- package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
- package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
- package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
- package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
- package/src/application/agent/providers/claude-code/provider.ts +717 -0
- package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
- package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
- package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
- package/src/application/agent/test-fixture.ts +131 -0
- package/src/application/agent/workspace.test.ts +104 -0
- package/src/application/agent/workspace.ts +156 -0
- package/src/application/dispatcher.test.ts +108 -0
- package/src/application/dispatcher.ts +106 -0
- package/src/application/index.ts +5 -0
- package/src/application/registry.ts +24 -0
- package/src/application/version.ts +7 -0
- package/src/commands/attach-exclude.ts +50 -0
- package/src/commands/attach-git.ts +50 -0
- package/src/commands/attach-store.ts +107 -0
- package/src/commands/attach.test.ts +192 -0
- package/src/commands/attach.ts +143 -0
- package/src/commands/clse.test.ts +181 -0
- package/src/commands/doctor.test.ts +29 -0
- package/src/commands/doctor.ts +78 -0
- package/src/commands/elicit.test.ts +111 -0
- package/src/commands/elicit.ts +188 -0
- package/src/commands/evolve.ts +209 -0
- package/src/commands/feature.test.ts +323 -0
- package/src/commands/feature.ts +405 -0
- package/src/commands/fix.test.ts +118 -0
- package/src/commands/fix.ts +58 -0
- package/src/commands/help.test.ts +33 -0
- package/src/commands/help.ts +35 -0
- package/src/commands/host-apply.ts +61 -0
- package/src/commands/host.test.ts +120 -0
- package/src/commands/host.ts +125 -0
- package/src/commands/index.ts +25 -0
- package/src/commands/init.test.ts +87 -0
- package/src/commands/init.ts +110 -0
- package/src/commands/inspect.test.ts +57 -0
- package/src/commands/inspect.ts +73 -0
- package/src/commands/install.test.ts +92 -0
- package/src/commands/install.ts +389 -0
- package/src/commands/journal.ts +118 -0
- package/src/commands/memory.ts +96 -0
- package/src/commands/new.test.ts +44 -0
- package/src/commands/new.ts +77 -0
- package/src/commands/next.test.ts +241 -0
- package/src/commands/next.ts +124 -0
- package/src/commands/optimize.ts +30 -0
- package/src/commands/plugin-linker.test.ts +219 -0
- package/src/commands/plugin-linker.ts +244 -0
- package/src/commands/refactor.ts +34 -0
- package/src/commands/skills-install-commit.ts +149 -0
- package/src/commands/skills-install-manifest.ts +124 -0
- package/src/commands/skills-install-report.ts +60 -0
- package/src/commands/skills-install-secure.ts +113 -0
- package/src/commands/skills-install.ts +245 -0
- package/src/commands/skills.test.ts +449 -0
- package/src/commands/skills.ts +247 -0
- package/src/commands/stack-commands.test.ts +67 -0
- package/src/commands/tier-c-conformance.test.ts +194 -0
- package/src/commands/types.ts +26 -0
- package/src/commands/uninstall.test.ts +122 -0
- package/src/commands/uninstall.ts +116 -0
- package/src/commands/validate-plan.test.ts +107 -0
- package/src/commands/validate-plan.ts +67 -0
- package/src/commands/validate-spec.test.ts +59 -0
- package/src/commands/validate-spec.ts +68 -0
- package/src/commands/verify.test.ts +117 -0
- package/src/commands/verify.ts +112 -0
- package/src/commands/version.test.ts +11 -0
- package/src/commands/version.ts +14 -0
- package/src/index.ts +30 -0
- package/src/output/formatter.ts +10 -0
- package/src/output/index.ts +2 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/providers/claude-code/provider.test.ts
|
|
2
|
+
//
|
|
3
|
+
// ClaudeCodeProvider tests (ADR-0019 PR4). A fake `claude` CLI fixture
|
|
4
|
+
// drives the REAL provider code path — spawn, live stream parsing, event
|
|
5
|
+
// emission, argv derivation, settlement — with no real binary and no
|
|
6
|
+
// network. The cross-process resume test goes through the REAL gateway so
|
|
7
|
+
// the persisted execution record, the encrypted session store, and the
|
|
8
|
+
// fresh-process resume are all exercised end to end.
|
|
9
|
+
//
|
|
10
|
+
// The acceptance criterion for PR4 ("a real provider executes a bounded
|
|
11
|
+
// task without bypassing the approved policy") has two halves: the
|
|
12
|
+
// policy-bypass half is proven HERE deterministically (argv + parity), and
|
|
13
|
+
// the real-provider half is proven by claude-code-smoke.test.ts when the
|
|
14
|
+
// claude CLI is available (visible skip otherwise).
|
|
15
|
+
|
|
16
|
+
import { promises as fs } from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
21
|
+
import {
|
|
22
|
+
AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
|
|
23
|
+
AGENT_CAPABILITIES,
|
|
24
|
+
computePolicyHash,
|
|
25
|
+
type AgentExecutionRequest,
|
|
26
|
+
type AgentPolicySnapshot,
|
|
27
|
+
type AgentProviderCapabilities,
|
|
28
|
+
} from '@agentic-sdlc-kit/contracts';
|
|
29
|
+
import { AgentGateway } from '../../gateway.js';
|
|
30
|
+
import { ClaudeCodeProvider } from './provider.js';
|
|
31
|
+
import { loadSessionRecord } from './resume-store.js';
|
|
32
|
+
|
|
33
|
+
const FIXTURE = path.join(
|
|
34
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
35
|
+
'fixtures',
|
|
36
|
+
'fake-claude.mjs',
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
let projectRoot: string;
|
|
40
|
+
let workspaceRoot: string;
|
|
41
|
+
let argvFile: string;
|
|
42
|
+
|
|
43
|
+
beforeEach(async () => {
|
|
44
|
+
projectRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-claude-provider-'));
|
|
45
|
+
workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-claude-ws-'));
|
|
46
|
+
argvFile = path.join(projectRoot, 'argv.json');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(async () => {
|
|
50
|
+
await fs.rm(projectRoot, { recursive: true, force: true });
|
|
51
|
+
await fs.rm(workspaceRoot, { recursive: true, force: true });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
function provider(mode: string, extra: Record<string, string> = {}): ClaudeCodeProvider {
|
|
55
|
+
return new ClaudeCodeProvider({
|
|
56
|
+
projectRoot,
|
|
57
|
+
cliPath: process.execPath,
|
|
58
|
+
cliArgvPrefix: [FIXTURE],
|
|
59
|
+
env: { FAKE_CLAUDE_MODE: mode, FAKE_CLAUDE_ARGV_FILE: argvFile, ...extra },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function snapshot(request: AgentExecutionRequest): AgentPolicySnapshot {
|
|
64
|
+
return {
|
|
65
|
+
schemaVersion: AGENT_POLICY_SNAPSHOT_SCHEMA_VERSION,
|
|
66
|
+
permissions: request.permissions,
|
|
67
|
+
budget: request.budget,
|
|
68
|
+
approvalPolicy: request.approvalPolicy,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function request(overrides: Partial<AgentExecutionRequest> = {}): AgentExecutionRequest {
|
|
73
|
+
const base: AgentExecutionRequest = {
|
|
74
|
+
schemaVersion: 2,
|
|
75
|
+
executionId: 'exec-RUN-001-TASK-001-red-1',
|
|
76
|
+
workflowRunId: 'RUN-001',
|
|
77
|
+
taskId: 'TASK-001',
|
|
78
|
+
providerId: 'claude-code',
|
|
79
|
+
taskKind: 'test_authoring',
|
|
80
|
+
policyHash: 'sha256:test-policy',
|
|
81
|
+
workspace: {
|
|
82
|
+
id: 'ws-run-001',
|
|
83
|
+
kind: 'git-worktree',
|
|
84
|
+
rootPath: workspaceRoot,
|
|
85
|
+
branch: 'kit/RUN-001',
|
|
86
|
+
baseCommitSha: 'a'.repeat(40),
|
|
87
|
+
createdAt: new Date().toISOString(),
|
|
88
|
+
},
|
|
89
|
+
instructions: 'Write the failing test for TASK-001.',
|
|
90
|
+
context: { specificationRef: 'docs/spec', planRef: 'docs/plan', relevantFiles: [], constraints: [] },
|
|
91
|
+
permissions: {
|
|
92
|
+
capabilities: ['repository.read', 'repository.write', 'process.test'],
|
|
93
|
+
writablePaths: [workspaceRoot],
|
|
94
|
+
networkAllowed: false,
|
|
95
|
+
},
|
|
96
|
+
budget: { maxDurationMs: 60_000, maxToolCalls: 40 },
|
|
97
|
+
approvalPolicy: { requireApprovalFor: ['external.approval'], allowAutonomousExecution: true },
|
|
98
|
+
...overrides,
|
|
99
|
+
};
|
|
100
|
+
base.policyHash = computePolicyHash(snapshot(base));
|
|
101
|
+
return base;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function readArgv(): Promise<{ argv: string[]; cwd: string; mode: string } | undefined> {
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(await fs.readFile(argvFile, 'utf8')) as { argv: string[]; cwd: string; mode: string };
|
|
107
|
+
} catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe('ClaudeCodeProvider — happy path', () => {
|
|
113
|
+
it('completes, reports honest usage, and never fabricates artifacts', async () => {
|
|
114
|
+
const req = request();
|
|
115
|
+
const handle = await provider('happy').start(req, new AbortController().signal);
|
|
116
|
+
const result = await handle.result();
|
|
117
|
+
|
|
118
|
+
expect(result.status).toBe('completed');
|
|
119
|
+
expect(result.summary).toContain('Done: created the marker file.');
|
|
120
|
+
expect(result.proposedArtifacts).toEqual([]); // claims are not evidence
|
|
121
|
+
expect(result.usage?.inputTokens).toBe(10);
|
|
122
|
+
expect(result.usage?.outputTokens).toBe(20);
|
|
123
|
+
expect(result.usage?.estimatedCost).toBe(0.003);
|
|
124
|
+
expect(result.usage?.currency).toBe('USD');
|
|
125
|
+
expect(result.usage?.durationMs).toBe(12);
|
|
126
|
+
expect(result.session?.sessionId).toBe('sess-fake-001');
|
|
127
|
+
expect(result.session?.resumeToken).toMatch(/^[A-Za-z0-9_-]{40,}$/);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('streams live events with monotonic sequences and the echoed policyHash', async () => {
|
|
131
|
+
const req = request();
|
|
132
|
+
const handle = await provider('happy').start(req, new AbortController().signal);
|
|
133
|
+
const events: unknown[] = [];
|
|
134
|
+
const unsubscribe = handle.events((e) => events.push(e));
|
|
135
|
+
const result = await handle.result();
|
|
136
|
+
unsubscribe();
|
|
137
|
+
|
|
138
|
+
// Late subscription replays the full stream (same contract as the mock).
|
|
139
|
+
const replayed: unknown[] = [];
|
|
140
|
+
handle.events((e) => replayed.push(e));
|
|
141
|
+
expect(replayed.length).toBe(events.length);
|
|
142
|
+
|
|
143
|
+
const types = events.map((e) => (e as { type: string }).type);
|
|
144
|
+
expect(types).toContain('execution.started');
|
|
145
|
+
expect(types).toContain('message.delta');
|
|
146
|
+
expect(types).toContain('execution.completed');
|
|
147
|
+
const requested = events.find((e) => (e as { type: string }).type === 'tool.requested') as {
|
|
148
|
+
toolCallId: string;
|
|
149
|
+
capability: string;
|
|
150
|
+
};
|
|
151
|
+
expect(requested.toolCallId).toBe('toolu_1');
|
|
152
|
+
expect(requested.capability).toBe('repository.write'); // inferred from the SAME table
|
|
153
|
+
const sequences = events.map((e) => (e as { sequence: number }).sequence);
|
|
154
|
+
expect(sequences).toEqual([...sequences].sort((a, b) => a - b));
|
|
155
|
+
for (const e of events) {
|
|
156
|
+
expect((e as { policyHash: string }).policyHash).toBe(req.policyHash);
|
|
157
|
+
expect((e as { executionId: string }).executionId).toBe(req.executionId);
|
|
158
|
+
}
|
|
159
|
+
const completed = events.find((e) => (e as { type: string }).type === 'execution.completed') as {
|
|
160
|
+
status: string;
|
|
161
|
+
};
|
|
162
|
+
expect(completed.status).toBe(result.status);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('builds the headless argv from the policy: scoped writes, allowlisted Bash, no bypass', async () => {
|
|
166
|
+
const req = request();
|
|
167
|
+
const handle = await provider('happy').start(req, new AbortController().signal);
|
|
168
|
+
await handle.result();
|
|
169
|
+
|
|
170
|
+
const captured = await readArgv();
|
|
171
|
+
expect(captured, 'fixture never wrote its argv').toBeDefined();
|
|
172
|
+
// macOS resolves /var -> /private/var in a child's process.cwd(), so
|
|
173
|
+
// compare REAL paths on both sides (identity on Linux).
|
|
174
|
+
expect(captured?.cwd).toBe(await fs.realpath(workspaceRoot));
|
|
175
|
+
expect(captured?.argv[0]).toBe('-p');
|
|
176
|
+
expect(captured?.argv[2]).toBe('--output-format');
|
|
177
|
+
expect(captured?.argv[3]).toBe('stream-json');
|
|
178
|
+
expect(captured?.argv).toContain('--verbose');
|
|
179
|
+
expect(captured?.argv).toContain('--permission-mode');
|
|
180
|
+
expect(captured?.argv).toContain('default');
|
|
181
|
+
const flat = captured?.argv.join(' ') ?? '';
|
|
182
|
+
expect(flat).toContain(`Write(${workspaceRoot}/**)`);
|
|
183
|
+
expect(flat).toContain('Bash(pnpm test:*)');
|
|
184
|
+
expect(captured?.argv).toContain('--max-turns');
|
|
185
|
+
expect(captured?.argv).toContain('40');
|
|
186
|
+
const disallowed = flat.slice(flat.indexOf('--disallowedTools') + '--disallowedTools'.length).split(' --')[0];
|
|
187
|
+
expect(disallowed).toContain('Task');
|
|
188
|
+
expect(disallowed).toContain('WebFetch');
|
|
189
|
+
expect(disallowed).toContain('WebSearch');
|
|
190
|
+
expect(flat).not.toContain('bypassPermissions');
|
|
191
|
+
expect(flat).not.toContain('--dangerously-skip-permissions');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('links runtime Mods into the workspace (parity) and reports honestly', async () => {
|
|
195
|
+
const handle = await provider('happy').start(request(), new AbortController().signal);
|
|
196
|
+
const result = await handle.result();
|
|
197
|
+
// Either the Mods linked (note says active) or they are honestly absent.
|
|
198
|
+
expect(result.summary).toMatch(/runtime Mods (active|NOT fully active)/);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('ClaudeCodeProvider — honest statuses (values, never completed)', () => {
|
|
203
|
+
it('already-aborted signal: cancelled without spawning', async () => {
|
|
204
|
+
const controller = new AbortController();
|
|
205
|
+
controller.abort();
|
|
206
|
+
const handle = await provider('happy').start(request(), controller.signal);
|
|
207
|
+
const result = await handle.result();
|
|
208
|
+
expect(result.status).toBe('cancelled');
|
|
209
|
+
expect(result.errors[0]?.code).toBe('CANCELLED');
|
|
210
|
+
expect(await readArgv()).toBeUndefined(); // never spawned
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('approval policy blocks autonomous runs that require approval, before spawning', async () => {
|
|
214
|
+
const req = request({
|
|
215
|
+
permissions: {
|
|
216
|
+
capabilities: ['repository.read', 'repository.write'],
|
|
217
|
+
writablePaths: [workspaceRoot],
|
|
218
|
+
networkAllowed: false,
|
|
219
|
+
},
|
|
220
|
+
approvalPolicy: { requireApprovalFor: ['repository.write'], allowAutonomousExecution: false },
|
|
221
|
+
});
|
|
222
|
+
const handle = await provider('happy').start(req, new AbortController().signal);
|
|
223
|
+
const result = await handle.result();
|
|
224
|
+
expect(result.status).toBe('needs_approval');
|
|
225
|
+
expect(result.errors[0]?.code).toBe('APPROVAL_REQUIRED');
|
|
226
|
+
expect(await readArgv()).toBeUndefined(); // blocked BEFORE touching the provider
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('mid-execution cancellation resolves a cancelled value, never a rejection', async () => {
|
|
230
|
+
const controller = new AbortController();
|
|
231
|
+
const handle = await provider('sleep').start(request(), controller.signal);
|
|
232
|
+
let abortAfterStart = false;
|
|
233
|
+
handle.events((e) => {
|
|
234
|
+
if ((e as { type: string }).type === 'execution.started' && !abortAfterStart) {
|
|
235
|
+
abortAfterStart = true;
|
|
236
|
+
setImmediate(() => controller.abort());
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const result = await handle.result();
|
|
240
|
+
expect(result.status).toBe('cancelled');
|
|
241
|
+
expect(result.errors[0]?.code).toBe('CANCELLED');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('max-turns breach maps to failed + BUDGET_EXCEEDED', async () => {
|
|
245
|
+
const handle = await provider('maxturns').start(request(), new AbortController().signal);
|
|
246
|
+
const result = await handle.result();
|
|
247
|
+
expect(result.status).toBe('failed');
|
|
248
|
+
expect(result.errors[0]?.code).toBe('BUDGET_EXCEEDED');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('execution errors map to failed + PROVIDER_INTERNAL', async () => {
|
|
252
|
+
const handle = await provider('error').start(request(), new AbortController().signal);
|
|
253
|
+
const result = await handle.result();
|
|
254
|
+
expect(result.status).toBe('failed');
|
|
255
|
+
expect(result.errors[0]?.code).toBe('PROVIDER_INTERNAL');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('permission denials map to failed + CAPABILITY_DENIED', async () => {
|
|
259
|
+
const handle = await provider('denied').start(request(), new AbortController().signal);
|
|
260
|
+
const result = await handle.result();
|
|
261
|
+
expect(result.status).toBe('failed');
|
|
262
|
+
expect(result.errors[0]?.code).toBe('CAPABILITY_DENIED');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('a killed process (signal, no result) maps to interrupted', async () => {
|
|
266
|
+
const handle = await provider('signal').start(request(), new AbortController().signal);
|
|
267
|
+
const result = await handle.result();
|
|
268
|
+
expect(result.status).toBe('interrupted');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('exit 0 without a result object (contract violation) maps to interrupted', async () => {
|
|
272
|
+
const handle = await provider('noresult').start(request(), new AbortController().signal);
|
|
273
|
+
const result = await handle.result();
|
|
274
|
+
expect(result.status).toBe('interrupted');
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('a non-zero exit without a result maps to failed (honest, never completed)', async () => {
|
|
278
|
+
const handle = await provider('crash').start(request(), new AbortController().signal);
|
|
279
|
+
const result = await handle.result();
|
|
280
|
+
expect(['failed', 'interrupted']).toContain(result.status);
|
|
281
|
+
expect(result.status).not.toBe('completed');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('output bound breach kills the process and reports BUDGET_EXCEEDED', async () => {
|
|
285
|
+
const p = new ClaudeCodeProvider({
|
|
286
|
+
projectRoot,
|
|
287
|
+
cliPath: process.execPath,
|
|
288
|
+
cliArgvPrefix: [FIXTURE],
|
|
289
|
+
maxOutputBytes: 4_096,
|
|
290
|
+
env: { FAKE_CLAUDE_MODE: 'flood', FAKE_CLAUDE_ARGV_FILE: argvFile },
|
|
291
|
+
});
|
|
292
|
+
const handle = await p.start(request(), new AbortController().signal);
|
|
293
|
+
const result = await handle.result();
|
|
294
|
+
expect(result.status).toBe('failed');
|
|
295
|
+
expect(result.errors[0]?.code).toBe('BUDGET_EXCEEDED');
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('ClaudeCodeProvider — capabilities and health', () => {
|
|
300
|
+
it('declares honest budget enforcement levels (revision C)', async () => {
|
|
301
|
+
const caps: AgentProviderCapabilities = await provider('happy').capabilities();
|
|
302
|
+
expect([...caps.capabilities].sort()).toEqual([...AGENT_CAPABILITIES].sort());
|
|
303
|
+
expect(caps.budgetEnforcement.maxDurationMs).toBe('gateway-enforced');
|
|
304
|
+
expect(caps.budgetEnforcement.maxToolCalls).toBe('gateway-enforced');
|
|
305
|
+
expect(caps.budgetEnforcement.maxInputTokens).toBe('best-effort');
|
|
306
|
+
expect(caps.budgetEnforcement.maxTotalTokens).toBe('best-effort');
|
|
307
|
+
expect(caps.budgetEnforcement.maxEstimatedCost).toBe('best-effort');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('healthCheck reports a missing binary honestly', async () => {
|
|
311
|
+
const missing = new ClaudeCodeProvider({
|
|
312
|
+
projectRoot,
|
|
313
|
+
cliPath: path.join(projectRoot, 'definitely-not-claude'),
|
|
314
|
+
});
|
|
315
|
+
const health = await missing.healthCheck();
|
|
316
|
+
expect(health.available).toBe(false);
|
|
317
|
+
expect(health.message).toContain('not found');
|
|
318
|
+
expect(health.message).toContain('install Claude Code');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('healthCheck succeeds against the fixture binary', async () => {
|
|
322
|
+
const health = await provider('happy').healthCheck();
|
|
323
|
+
expect(health.available).toBe(true);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('ClaudeCodeProvider — cross-process resume (PR4 deferred item)', () => {
|
|
328
|
+
it('resumes through a FRESH gateway using the encrypted store, and the token never lands in plaintext', async () => {
|
|
329
|
+
const req = request({ executionId: 'exec-RUN-005-TASK-001-red-1' });
|
|
330
|
+
const firstGateway = new AgentGateway({ providers: [provider('happy')], projectRoot });
|
|
331
|
+
const first = await firstGateway.start(req, { policySnapshot: snapshot(req) });
|
|
332
|
+
expect(first.ok, first.ok ? '' : JSON.stringify(first.error)).toBe(true);
|
|
333
|
+
if (!first.ok) return;
|
|
334
|
+
expect(first.value.status).toBe('completed');
|
|
335
|
+
|
|
336
|
+
// The encrypted session record exists; the gateway's own persisted
|
|
337
|
+
// execution record contains NO token.
|
|
338
|
+
const record = await loadSessionRecord(projectRoot, req.executionId);
|
|
339
|
+
expect(record?.sessionId).toBe('sess-fake-001');
|
|
340
|
+
const persistedExecution = await fs.readFile(
|
|
341
|
+
path.join(projectRoot, '.ai-kit', 'state', 'agent-executions', `${req.executionId}.json`),
|
|
342
|
+
'utf8',
|
|
343
|
+
);
|
|
344
|
+
if (record) expect(persistedExecution).not.toContain(record.resumeToken);
|
|
345
|
+
|
|
346
|
+
// A NEW process: fresh gateway + fresh provider. The "CLI" reads the
|
|
347
|
+
// credential from the encrypted store and presents it to resume().
|
|
348
|
+
const freshGateway = new AgentGateway({ providers: [provider('resume')], projectRoot });
|
|
349
|
+
const resumed = await freshGateway.resume(req.executionId, record?.resumeToken ?? 'wrong');
|
|
350
|
+
expect(resumed.ok).toBe(true);
|
|
351
|
+
if (!resumed.ok) return;
|
|
352
|
+
expect(resumed.value.status).toBe('completed');
|
|
353
|
+
expect(resumed.value.attempts).toBe(2);
|
|
354
|
+
|
|
355
|
+
// The resumed invocation addressed the provider session by id.
|
|
356
|
+
const captured = await readArgv();
|
|
357
|
+
expect(captured?.argv).toContain('--resume');
|
|
358
|
+
expect(captured?.argv).toContain('sess-fake-001');
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('a wrong resume token fails closed with SESSION_EXPIRED', async () => {
|
|
362
|
+
const req = request({ executionId: 'exec-RUN-006-TASK-001-red-1' });
|
|
363
|
+
const firstGateway = new AgentGateway({ providers: [provider('happy')], projectRoot });
|
|
364
|
+
const first = await firstGateway.start(req, { policySnapshot: snapshot(req) });
|
|
365
|
+
expect(first.ok, first.ok ? '' : JSON.stringify(first.error)).toBe(true);
|
|
366
|
+
|
|
367
|
+
const freshGateway = new AgentGateway({ providers: [provider('resume')], projectRoot });
|
|
368
|
+
const resumed = await freshGateway.resume(req.executionId, 'forged-token');
|
|
369
|
+
expect(resumed.ok, resumed.ok ? '' : JSON.stringify(resumed.error)).toBe(true);
|
|
370
|
+
if (!resumed.ok) return;
|
|
371
|
+
expect(resumed.value.status).toBe('failed');
|
|
372
|
+
expect(resumed.value.result?.errors[0]?.code).toBe('SESSION_EXPIRED');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('cancel() of an unknown executionId is a no-op', async () => {
|
|
376
|
+
await expect(provider('happy').cancel('exec-never-started')).resolves.toBeUndefined();
|
|
377
|
+
});
|
|
378
|
+
});
|