@duct-sdk/sdk 0.5.13 → 0.6.0

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +385 -344
  2. package/README.md +418 -264
  3. package/TOKEN_SPEC.md +243 -243
  4. package/dist/cli/add.d.ts +7 -0
  5. package/dist/cli/add.js +152 -0
  6. package/dist/cli/agent-prompt.d.ts +3 -0
  7. package/dist/cli/agent-prompt.js +39 -0
  8. package/dist/cli/api-sources.d.ts +26 -0
  9. package/dist/cli/api-sources.js +222 -0
  10. package/dist/cli/cloud.d.ts +133 -0
  11. package/dist/cli/cloud.js +298 -0
  12. package/dist/cli/config-loader.d.ts +14 -0
  13. package/dist/cli/config-loader.js +56 -7
  14. package/dist/cli/device-login.d.ts +17 -0
  15. package/dist/cli/device-login.js +75 -0
  16. package/dist/cli/drift.js +6 -6
  17. package/dist/cli/generators/any-stack.d.ts +3 -0
  18. package/dist/cli/generators/any-stack.js +97 -0
  19. package/dist/cli/generators/config.js +3 -2
  20. package/dist/cli/generators/receiver.js +7 -7
  21. package/dist/cli/generators/shell.js +12 -12
  22. package/dist/cli/generators/token-route.js +245 -245
  23. package/dist/cli/index.js +396 -611
  24. package/dist/cli/mcp-core.d.ts +42 -0
  25. package/dist/cli/mcp-core.js +161 -0
  26. package/dist/cli/mcp-setup.d.ts +4 -0
  27. package/dist/cli/mcp-setup.js +360 -0
  28. package/dist/cli/mcp.d.ts +2 -0
  29. package/dist/cli/mcp.js +457 -0
  30. package/dist/cli/migrate-intershell.js +5 -5
  31. package/dist/cli/policy-defaults.d.ts +37 -0
  32. package/dist/cli/policy-defaults.js +127 -0
  33. package/dist/cli/processors/integration-audit.js +2 -2
  34. package/dist/cli/processors/openapi-parser.d.ts +5 -0
  35. package/dist/cli/processors/openapi-parser.js +8 -3
  36. package/dist/cli/project-loader.d.ts +58 -0
  37. package/dist/cli/project-loader.js +198 -0
  38. package/dist/cli/project-writer.d.ts +23 -0
  39. package/dist/cli/project-writer.js +171 -0
  40. package/dist/cli/push.d.ts +43 -0
  41. package/dist/cli/push.js +276 -0
  42. package/dist/cli/safety-checks.d.ts +9 -0
  43. package/dist/cli/safety-checks.js +29 -0
  44. package/dist/cli/setup.d.ts +20 -0
  45. package/dist/cli/setup.js +349 -0
  46. package/dist/cli/shell-name.d.ts +8 -0
  47. package/dist/cli/shell-name.js +29 -0
  48. package/dist/cli/shells.d.ts +22 -0
  49. package/dist/cli/shells.js +122 -0
  50. package/dist/cli/split.d.ts +7 -0
  51. package/dist/cli/split.js +71 -0
  52. package/dist/cli/sync.d.ts +25 -0
  53. package/dist/cli/sync.js +120 -0
  54. package/dist/cli/test-runner.d.ts +21 -0
  55. package/dist/cli/test-runner.js +281 -0
  56. package/dist/core/compile.d.ts +43 -0
  57. package/dist/core/compile.js +510 -0
  58. package/dist/core/config.d.ts +464 -1
  59. package/dist/core/config.js +14 -14
  60. package/dist/core/login-handoff.d.ts +1 -1
  61. package/dist/core/login-handoff.js +1 -1
  62. package/dist/core/project.d.ts +1798 -0
  63. package/dist/core/project.js +278 -0
  64. package/dist/core/readiness-checks.js +2 -2
  65. package/dist/core/types.d.ts +1 -1
  66. package/dist/index.d.ts +2 -0
  67. package/dist/index.js +1 -0
  68. package/dist/project.d.ts +4 -0
  69. package/dist/project.js +8 -0
  70. package/dist/server.d.ts +2 -0
  71. package/dist/server.js +1 -0
  72. package/package.json +94 -95
  73. package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
  74. package/dist/adapters/react/page-context-guard.test.js +0 -15
  75. package/dist/cli/agents/api-agent.d.ts +0 -22
  76. package/dist/cli/agents/api-agent.js +0 -761
  77. package/dist/cli/agents/auth-agent.d.ts +0 -7
  78. package/dist/cli/agents/auth-agent.js +0 -212
  79. package/dist/cli/agents/deeplink-agent.d.ts +0 -6
  80. package/dist/cli/agents/deeplink-agent.js +0 -285
  81. package/dist/cli/agents/llm.d.ts +0 -33
  82. package/dist/cli/agents/llm.js +0 -309
  83. package/dist/cli/agents/pipeline.d.ts +0 -72
  84. package/dist/cli/agents/pipeline.js +0 -421
  85. package/dist/cli/agents/reviewer-agent.d.ts +0 -13
  86. package/dist/cli/agents/reviewer-agent.js +0 -450
  87. package/dist/cli/agents/route-agent.d.ts +0 -17
  88. package/dist/cli/agents/route-agent.js +0 -383
  89. package/dist/cli/config-loader.test.d.ts +0 -1
  90. package/dist/cli/config-loader.test.js +0 -63
  91. package/dist/cli/detectors/topology.d.ts +0 -46
  92. package/dist/cli/detectors/topology.js +0 -417
  93. package/dist/cli/generators/config.test.d.ts +0 -1
  94. package/dist/cli/generators/config.test.js +0 -222
  95. package/dist/cli/generators/shell.test.d.ts +0 -1
  96. package/dist/cli/generators/shell.test.js +0 -73
  97. package/dist/cli/generators/token-route.test.d.ts +0 -1
  98. package/dist/cli/generators/token-route.test.js +0 -53
  99. package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
  100. package/dist/cli/generators/wiring-snippets.test.js +0 -80
  101. package/dist/cli/init.d.ts +0 -32
  102. package/dist/cli/init.js +0 -1336
  103. package/dist/cli/manifest-diff.test.d.ts +0 -1
  104. package/dist/cli/manifest-diff.test.js +0 -144
  105. package/dist/cli/processors/curl-parser.test.d.ts +0 -1
  106. package/dist/cli/processors/curl-parser.test.js +0 -24
  107. package/dist/cli/processors/integration-audit.test.d.ts +0 -1
  108. package/dist/cli/processors/integration-audit.test.js +0 -154
  109. package/dist/cli/processors/postprocess.d.ts +0 -22
  110. package/dist/cli/processors/postprocess.js +0 -107
  111. package/dist/cli/processors/prisma-parser.d.ts +0 -35
  112. package/dist/cli/processors/prisma-parser.js +0 -117
  113. package/dist/cli/processors/verify-discovery.d.ts +0 -33
  114. package/dist/cli/processors/verify-discovery.js +0 -193
  115. package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
  116. package/dist/cli/processors/verify-discovery.test.js +0 -153
  117. package/dist/cli/processors/zod-extractor.d.ts +0 -27
  118. package/dist/cli/processors/zod-extractor.js +0 -153
  119. package/dist/cli/prompts/review.d.ts +0 -61
  120. package/dist/cli/prompts/review.js +0 -410
  121. package/dist/cli/selectors/express.d.ts +0 -12
  122. package/dist/cli/selectors/express.js +0 -117
  123. package/dist/cli/selectors/fastapi.d.ts +0 -12
  124. package/dist/cli/selectors/fastapi.js +0 -122
  125. package/dist/cli/selectors/generic.d.ts +0 -10
  126. package/dist/cli/selectors/generic.js +0 -74
  127. package/dist/cli/selectors/index.d.ts +0 -37
  128. package/dist/cli/selectors/index.js +0 -315
  129. package/dist/cli/selectors/next.d.ts +0 -12
  130. package/dist/cli/selectors/next.js +0 -130
  131. package/dist/core/config-policy.test.d.ts +0 -1
  132. package/dist/core/config-policy.test.js +0 -101
  133. package/dist/core/config-roundtrip.test.d.ts +0 -1
  134. package/dist/core/config-roundtrip.test.js +0 -180
  135. package/dist/core/endpoint-guard.test.d.ts +0 -1
  136. package/dist/core/endpoint-guard.test.js +0 -57
  137. package/dist/core/env-diagnostics.test.d.ts +0 -1
  138. package/dist/core/env-diagnostics.test.js +0 -31
  139. package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
  140. package/dist/core/evidence-bundle.conformance.test.js +0 -110
  141. package/dist/core/evidence-bundle.test.d.ts +0 -1
  142. package/dist/core/evidence-bundle.test.js +0 -58
  143. package/dist/core/invariants.test.d.ts +0 -1
  144. package/dist/core/invariants.test.js +0 -217
  145. package/dist/core/login-handoff.test.d.ts +0 -1
  146. package/dist/core/login-handoff.test.js +0 -31
  147. package/dist/core/profile.test.d.ts +0 -1
  148. package/dist/core/profile.test.js +0 -95
  149. package/dist/core/readiness-checks.test.d.ts +0 -1
  150. package/dist/core/readiness-checks.test.js +0 -106
  151. package/dist/core/receipt.test.d.ts +0 -1
  152. package/dist/core/receipt.test.js +0 -75
  153. package/dist/core/sdk-entrypoint.test.d.ts +0 -1
  154. package/dist/core/sdk-entrypoint.test.js +0 -8
  155. package/dist/core/side-effects-review.test.d.ts +0 -1
  156. package/dist/core/side-effects-review.test.js +0 -28
  157. package/dist/core/token.conformance.test.d.ts +0 -1
  158. package/dist/core/token.conformance.test.js +0 -43
  159. package/dist/core/token.test.d.ts +0 -1
  160. package/dist/core/token.test.js +0 -66
@@ -1,180 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { defineDuctConfig, validateDuctConfigStrict } from "./config.js";
4
- function minimalConfig(overrides = {}) {
5
- return {
6
- shellId: "shell_acme_prod",
7
- product: {
8
- name: "Acme",
9
- description: "Test",
10
- baseUrl: "https://app.acme.com",
11
- },
12
- auth: {
13
- strategy: "session-cookie",
14
- sessionFields: ["id"],
15
- guestAllowed: false,
16
- tokenExpirySeconds: 60,
17
- },
18
- routes: [],
19
- actions: [
20
- {
21
- id: "list_orders",
22
- name: "List orders",
23
- description: "List orders",
24
- method: "GET",
25
- path: "/api/orders",
26
- agentAccessible: true,
27
- sideEffects: false,
28
- sensitivityLevel: "low",
29
- params: [],
30
- requiresAuth: true,
31
- },
32
- ],
33
- deeplinks: [],
34
- agentPermissions: {
35
- defaultLevel: "none",
36
- requireUserConsent: true,
37
- },
38
- ...overrides,
39
- };
40
- }
41
- describe("config field round-trip", () => {
42
- it("preserves action inputSchema, dependsOn, and semantic metadata", () => {
43
- const inputSchema = {
44
- type: "object",
45
- properties: { q: { type: "string" } },
46
- };
47
- const outputSchema = {
48
- type: "array",
49
- items: { type: "object" },
50
- };
51
- const config = minimalConfig({
52
- actions: [
53
- {
54
- ...minimalConfig().actions[0],
55
- sensitivityLevel: "critical",
56
- inputSchema,
57
- dependsOn: [
58
- {
59
- actionId: "list_orders",
60
- paramMapping: { orderId: "id" },
61
- },
62
- ],
63
- semanticType: "search_results",
64
- outputSchema,
65
- paramMappings: { orderId: "id" },
66
- navigatesTo: "order_detail",
67
- searchHint: "Search orders",
68
- alwaysInclude: true,
69
- interruptBehavior: "block",
70
- },
71
- ],
72
- });
73
- const result = validateDuctConfigStrict(config);
74
- assert.equal(result.ok, true);
75
- if (!result.ok)
76
- return;
77
- const action = result.data.actions[0];
78
- assert.deepEqual(action.inputSchema, inputSchema);
79
- assert.deepEqual(action.dependsOn, [
80
- { actionId: "list_orders", paramMapping: { orderId: "id" } },
81
- ]);
82
- assert.equal(action.semanticType, "search_results");
83
- assert.deepEqual(action.outputSchema, outputSchema);
84
- assert.deepEqual(action.paramMappings, { orderId: "id" });
85
- assert.equal(action.navigatesTo, "order_detail");
86
- assert.equal(action.sensitivityLevel, "critical");
87
- assert.equal(action.searchHint, "Search orders");
88
- assert.equal(action.alwaysInclude, true);
89
- assert.equal(action.interruptBehavior, "block");
90
- });
91
- it("preserves dataModel and widget loop limits", () => {
92
- const dataModel = {
93
- entities: [
94
- {
95
- id: "order",
96
- label: "Order",
97
- discoveryAction: "list_orders",
98
- fetchAction: "get_order",
99
- indexKey: "id",
100
- labelKey: "name",
101
- dimensions: ["status"],
102
- },
103
- ],
104
- };
105
- const widget = {
106
- compactionTurns: 4,
107
- maxToolIterations: 10,
108
- maxPlanSteps: 6,
109
- };
110
- const config = minimalConfig({ dataModel, widget });
111
- const parsed = defineDuctConfig(config);
112
- assert.deepEqual(parsed.dataModel, dataModel);
113
- assert.equal(parsed.widget?.compactionTurns, 4);
114
- assert.equal(parsed.widget?.maxToolIterations, 10);
115
- assert.equal(parsed.widget?.maxPlanSteps, 6);
116
- });
117
- it("accepts sensitivityLevel none on actions", () => {
118
- const config = minimalConfig({
119
- actions: [
120
- {
121
- ...minimalConfig().actions[0],
122
- sensitivityLevel: "none",
123
- },
124
- ],
125
- });
126
- const result = validateDuctConfigStrict(config);
127
- assert.equal(result.ok, true);
128
- if (result.ok) {
129
- assert.equal(result.data.actions[0].sensitivityLevel, "none");
130
- }
131
- });
132
- it("preserves allowedCallees and webhooks (intershell egress + identity config)", () => {
133
- const config = minimalConfig({
134
- intershell_enabled: true,
135
- registry_visibility: "public",
136
- agentPermissions: {
137
- defaultLevel: "none",
138
- requireUserConsent: true,
139
- allowedCallees: ["shell_partner_prod", "*"],
140
- },
141
- webhooks: {
142
- consentCallback: "https://app.acme.com/duct/consent-callback",
143
- identityUrl: "https://app.acme.com/duct/identity",
144
- secret: "whsec_test123",
145
- },
146
- });
147
- const result = validateDuctConfigStrict(config);
148
- assert.equal(result.ok, true);
149
- if (!result.ok)
150
- return;
151
- assert.deepEqual(result.data.agentPermissions.allowedCallees, [
152
- "shell_partner_prod",
153
- "*",
154
- ]);
155
- assert.equal(result.data.webhooks?.identityUrl, "https://app.acme.com/duct/identity");
156
- assert.equal(result.data.webhooks?.secret, "whsec_test123");
157
- });
158
- it("rejects a malformed allowedCallees entry", () => {
159
- const config = minimalConfig({
160
- agentPermissions: {
161
- defaultLevel: "none",
162
- requireUserConsent: true,
163
- allowedCallees: ["not-a-valid-shell-id"],
164
- },
165
- });
166
- const result = validateDuctConfigStrict(config);
167
- assert.equal(result.ok, false);
168
- });
169
- it("flags intershell_enabled shells with a protected action but no webhooks.identityUrl", () => {
170
- const config = minimalConfig({
171
- intershell_enabled: true,
172
- registry_visibility: "public",
173
- });
174
- const result = validateDuctConfigStrict(config);
175
- assert.equal(result.ok, false);
176
- if (result.ok)
177
- return;
178
- assert.ok(result.issues.some((issue) => issue.issue.includes("webhooks.identityUrl")));
179
- });
180
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,57 +0,0 @@
1
- import { describe, it, beforeEach, afterEach } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { allowsLocalhostEndpoints, assertHostedEndpointsNotLocalhost, getDuctProfile, HostedLocalhostEndpointError, isLocalhostUrl, } from "./endpoint-guard.js";
4
- const ORIGINAL_ENV = { ...process.env };
5
- function restoreEnv() {
6
- for (const key of Object.keys(process.env)) {
7
- if (!(key in ORIGINAL_ENV))
8
- delete process.env[key];
9
- }
10
- for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
11
- if (value === undefined)
12
- delete process.env[key];
13
- else
14
- process.env[key] = value;
15
- }
16
- }
17
- describe("endpoint-guard", () => {
18
- beforeEach(() => {
19
- delete process.env.DUCT_PROFILE;
20
- delete process.env.DUCT_ALLOW_LOCALHOST;
21
- delete process.env.DUCT_URL;
22
- delete process.env.DUCT_AUTH_URL;
23
- delete process.env.DUCT_API_URL;
24
- delete process.env.DUCT_SHELL_URL;
25
- delete process.env.DUCT_DASHBOARD_URL;
26
- delete process.env.DUCT_REGISTRY_URL;
27
- });
28
- afterEach(() => {
29
- restoreEnv();
30
- });
31
- it("detects localhost URLs", () => {
32
- assert.equal(isLocalhostUrl("http://localhost:3002"), true);
33
- assert.equal(isLocalhostUrl("http://127.0.0.1:3001"), true);
34
- assert.equal(isLocalhostUrl("https://api.example.com"), false);
35
- });
36
- it("treats DUCT_PROFILE=local as allowing localhost", () => {
37
- process.env.DUCT_PROFILE = "local";
38
- assert.equal(getDuctProfile(), "local");
39
- assert.equal(allowsLocalhostEndpoints(), true);
40
- assert.doesNotThrow(() => assertHostedEndpointsNotLocalhost());
41
- });
42
- it("fails hosted mode when endpoints resolve to localhost", () => {
43
- assert.throws(() => assertHostedEndpointsNotLocalhost(), (err) => {
44
- assert.ok(err instanceof HostedLocalhostEndpointError);
45
- assert.ok(err.localhostEndpoints.length > 0);
46
- return true;
47
- });
48
- });
49
- it("allows localhost in hosted mode when DUCT_ALLOW_LOCALHOST=true", () => {
50
- process.env.DUCT_ALLOW_LOCALHOST = "true";
51
- assert.doesNotThrow(() => assertHostedEndpointsNotLocalhost());
52
- });
53
- it("passes hosted mode when DUCT_URL points to a remote origin", () => {
54
- process.env.DUCT_URL = "https://acme.duct.dev";
55
- assert.doesNotThrow(() => assertHostedEndpointsNotLocalhost());
56
- });
57
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { collectEnvDiagnosticLines, redactEnvValue, shouldRedactEnvKey, } from "./env-diagnostics.js";
4
- describe("env-diagnostics", () => {
5
- it("flags secret-like env keys for redaction", () => {
6
- assert.equal(shouldRedactEnvKey("DUCT_SECRET_KEY"), true);
7
- assert.equal(shouldRedactEnvKey("DUCT_SHELL_ID"), false);
8
- assert.equal(shouldRedactEnvKey("MY_AUTH_TOKEN"), true);
9
- });
10
- it("redacts secret values while preserving shape", () => {
11
- assert.equal(redactEnvValue("DUCT_API_KEY", "dk_live_abcdefghijklmnop"), "dk_l...mnop");
12
- assert.equal(redactEnvValue("DUCT_SHELL_ID", "shell_acme_prod"), "shell_acme_prod");
13
- });
14
- it("collectEnvDiagnosticLines redacts tracked secrets when requested", () => {
15
- const previous = process.env.DUCT_API_KEY;
16
- process.env.DUCT_API_KEY = "dk_live_secretvalue123456";
17
- try {
18
- const lines = collectEnvDiagnosticLines(null, { redact: true });
19
- const apiKeyLine = lines.find((line) => line.key === "DUCT_API_KEY");
20
- assert.ok(apiKeyLine);
21
- assert.match(apiKeyLine.value, /\.\.\./);
22
- assert.doesNotMatch(apiKeyLine.value, /secretvalue123456/);
23
- }
24
- finally {
25
- if (previous === undefined)
26
- delete process.env.DUCT_API_KEY;
27
- else
28
- process.env.DUCT_API_KEY = previous;
29
- }
30
- });
31
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,110 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { createHmac } from 'crypto';
4
- import { verifyEvidenceBundle } from './evidence-bundle.js';
5
- import { computeReceiptId } from './receipt.js';
6
- import { canonicalizeJson } from './jcs.js';
7
- const HMAC_SECRET = 'conformance-fixture-secret-32bytes!!';
8
- function signReceipt(body) {
9
- const receipt_id = computeReceiptId(body);
10
- const signature = createHmac('sha256', HMAC_SECRET).update(canonicalizeJson(body)).digest('hex');
11
- return { ...body, receipt_id, signature, kid: 'duct-gateway-hs256-v1' };
12
- }
13
- function goldenReadActionBundle() {
14
- const gate = signReceipt({
15
- claim_type: 'duct:action:v1',
16
- issued_at: '2026-01-01T00:00:01.000Z',
17
- shell_id: 'shell_fixture',
18
- action_id: 'get_items',
19
- caller_type: 'human',
20
- decision: 'permit',
21
- reason: 'Passes all permission checks',
22
- permission_source: 'default',
23
- capture_mode: 'gateway_observed',
24
- scope_of_claim: {
25
- asserts: ['gate'],
26
- does_not_assert: ['upstream'],
27
- },
28
- });
29
- const execution = signReceipt({
30
- claim_type: 'duct:execution:v1',
31
- issued_at: '2026-01-01T00:00:05.000Z',
32
- shell_id: 'shell_fixture',
33
- action_id: 'get_items',
34
- caller_type: 'human',
35
- decision: 'permit',
36
- reason: 'upstream_observed',
37
- permission_source: 'gateway',
38
- capture_mode: 'gateway_observed',
39
- scope_of_claim: {
40
- asserts: ['dispatch'],
41
- does_not_assert: ['business correctness'],
42
- },
43
- gate_receipt_ref: gate.receipt_id,
44
- execution_id: 'EX123',
45
- upstream_status_class: 'success',
46
- });
47
- return {
48
- manifest: {
49
- schema: 'duct:audit-evidence:v1',
50
- bundle_id: 'fixture-read-action',
51
- exported_at: '2026-01-01T00:10:00.000Z',
52
- shell_id: 'shell_fixture',
53
- company_id: 'co_fixture',
54
- profile: 'standard',
55
- completeness: 'complete',
56
- complete: true,
57
- non_claims: [
58
- 'does_not_assert_llm_reasoning_correctness',
59
- 'does_not_assert_upstream_business_data_correctness',
60
- ],
61
- },
62
- conversation: [
63
- {
64
- turn_id: 't_fixture',
65
- message_preview: 'show my items',
66
- reply_preview: 'Here are your items.',
67
- occurred_at: '2026-01-01T00:00:00.000Z',
68
- },
69
- ],
70
- evidence_events: [
71
- { stage: 'request_observed' },
72
- { stage: 'action_selected' },
73
- { stage: 'policy_decided' },
74
- { stage: 'upstream_dispatched' },
75
- { stage: 'upstream_completed' },
76
- { stage: 'response_delivered' },
77
- ],
78
- receipts: [gate, execution],
79
- redaction_ledger: [],
80
- integrity: { valid: true, window_size: 1 },
81
- replay_descriptor: {
82
- executions: [
83
- {
84
- execution_id: 'EX123',
85
- action_id: 'get_items',
86
- request_hash: 'abc123',
87
- result_hash: 'def456',
88
- },
89
- ],
90
- sandbox_only: true,
91
- requires_fresh_approval: true,
92
- },
93
- };
94
- }
95
- describe('evidence bundle conformance fixtures', () => {
96
- it('verifies the golden read-action scenario', () => {
97
- const bundle = goldenReadActionBundle();
98
- const result = verifyEvidenceBundle(bundle, { hmacSecret: HMAC_SECRET });
99
- assert.equal(result.valid, true);
100
- assert.equal(result.verified_receipts, 2);
101
- assert.equal(result.completeness, 'complete');
102
- assert.deepEqual(result.missing_stages, []);
103
- });
104
- it('flags partial bundles with warnings', () => {
105
- const bundle = goldenReadActionBundle();
106
- bundle.manifest.completeness = 'partial';
107
- const result = verifyEvidenceBundle(bundle, { hmacSecret: HMAC_SECRET });
108
- assert.ok(result.warnings.some((w) => w.includes('partial')));
109
- });
110
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { createHmac } from 'crypto';
4
- import { verifyEvidenceBundle } from './evidence-bundle.js';
5
- import { computeReceiptId } from './receipt.js';
6
- import { canonicalizeJson } from './jcs.js';
7
- const HMAC_SECRET = 'x'.repeat(32);
8
- function minimalReceipt() {
9
- const body = {
10
- claim_type: 'duct:action:v1',
11
- issued_at: new Date().toISOString(),
12
- shell_id: 'shell_test',
13
- action_id: 'get_items',
14
- caller_type: 'human',
15
- decision: 'permit',
16
- reason: 'Passes all permission checks',
17
- permission_source: 'default',
18
- capture_mode: 'gateway_observed',
19
- scope_of_claim: {
20
- asserts: ['test'],
21
- does_not_assert: ['test'],
22
- },
23
- };
24
- const receipt_id = computeReceiptId(body);
25
- const canonical = canonicalizeJson(body);
26
- const signature = createHmac('sha256', HMAC_SECRET).update(canonical).digest('hex');
27
- return { ...body, receipt_id, signature, kid: 'duct-gateway-hs256-v1' };
28
- }
29
- describe('verifyEvidenceBundle', () => {
30
- it('validates a minimal complete bundle', () => {
31
- const receipt = minimalReceipt();
32
- const result = verifyEvidenceBundle({
33
- manifest: {
34
- schema: 'duct:audit-evidence:v1',
35
- bundle_id: 'b1',
36
- exported_at: new Date().toISOString(),
37
- shell_id: 'shell_test',
38
- company_id: 'co_1',
39
- profile: 'standard',
40
- completeness: 'complete',
41
- complete: true,
42
- },
43
- conversation: [],
44
- evidence_events: [
45
- { stage: 'request_observed' },
46
- { stage: 'policy_decided' },
47
- { stage: 'upstream_dispatched' },
48
- { stage: 'upstream_completed' },
49
- { stage: 'response_delivered' },
50
- ],
51
- receipts: [receipt],
52
- redaction_ledger: [],
53
- integrity: { valid: true, window_size: 1 },
54
- }, { hmacSecret: HMAC_SECRET });
55
- assert.equal(result.valid, true);
56
- assert.equal(result.verified_receipts, 1);
57
- });
58
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,217 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { createHmac } from "crypto";
4
- import { SignJWT } from "jose";
5
- import { generateShell } from "../cli/generators/shell.js";
6
- import { canonicalizeJson } from "./jcs.js";
7
- import { computeReceiptId, verifyReceipt, } from "./receipt.js";
8
- import { generateDeeplinkToken, verifyDeeplinkToken, generateDuctToken, verifyDuctToken, createDevReplayStore, } from "./token.js";
9
- const SECRET = "test-secret-key-at-least-32-chars-long";
10
- const SHELL_ID = "shell_test_prod";
11
- const HMAC_SECRET = "01234567890123456789012345678901";
12
- function encodeSecret(secret) {
13
- return new TextEncoder().encode(secret);
14
- }
15
- function unsignedJwt(payload) {
16
- const header = Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString("base64url");
17
- const body = Buffer.from(JSON.stringify(payload)).toString("base64url");
18
- return `${header}.${body}.`;
19
- }
20
- function signTestReceipt(body) {
21
- const receipt_id = computeReceiptId(body);
22
- const canonical = canonicalizeJson(body);
23
- const signature = createHmac("sha256", HMAC_SECRET).update(canonical).digest("hex");
24
- return { ...body, receipt_id, signature, kid: "duct-gateway-hs256-v1" };
25
- }
26
- const minimalConfig = {
27
- shellId: "shell_test",
28
- product: {
29
- name: "Test",
30
- description: "Test product",
31
- baseUrl: "https://app.example.com",
32
- },
33
- };
34
- describe("P6-INV-4 token verifiers pin algorithms", () => {
35
- it("verifyDuctToken rejects HS512 and alg:none tokens", async () => {
36
- const hs512 = await new SignJWT({ type: "duct_delegated", session: {} })
37
- .setProtectedHeader({ alg: "HS512" })
38
- .setSubject("u_1")
39
- .setIssuer(SHELL_ID)
40
- .setIssuedAt()
41
- .setExpirationTime("1h")
42
- .sign(encodeSecret(SECRET));
43
- const hs512Result = await verifyDuctToken(hs512, {
44
- secretKey: SECRET,
45
- expectedShellId: SHELL_ID,
46
- });
47
- assert.equal(hs512Result.valid, false);
48
- const noneToken = unsignedJwt({
49
- type: "duct_delegated",
50
- sub: "u_1",
51
- iss: SHELL_ID,
52
- exp: Math.floor(Date.now() / 1000) + 3600,
53
- });
54
- const noneResult = await verifyDuctToken(noneToken, {
55
- secretKey: SECRET,
56
- expectedShellId: SHELL_ID,
57
- });
58
- assert.equal(noneResult.valid, false);
59
- });
60
- it("verifyDeeplinkToken rejects HS512 and alg:none tokens", async () => {
61
- const hs512 = await new SignJWT({ deeplink_id: "view_order", state: {} })
62
- .setProtectedHeader({ alg: "HS512" })
63
- .setIssuer(SHELL_ID)
64
- .setAudience(SHELL_ID)
65
- .setJti(crypto.randomUUID())
66
- .setIssuedAt()
67
- .setExpirationTime("1h")
68
- .sign(encodeSecret(SECRET));
69
- const hs512Result = await verifyDeeplinkToken(hs512, {
70
- secretKey: SECRET,
71
- expectedShellId: SHELL_ID,
72
- });
73
- assert.equal(hs512Result.valid, false);
74
- const noneToken = unsignedJwt({
75
- deeplink_id: "view_order",
76
- iss: SHELL_ID,
77
- aud: SHELL_ID,
78
- jti: crypto.randomUUID(),
79
- exp: Math.floor(Date.now() / 1000) + 3600,
80
- });
81
- const noneResult = await verifyDeeplinkToken(noneToken, {
82
- secretKey: SECRET,
83
- expectedShellId: SHELL_ID,
84
- });
85
- assert.equal(noneResult.valid, false);
86
- });
87
- it("verifyReceipt rejects unknown kid / non-HS256 HMAC path", () => {
88
- const body = {
89
- claim_type: "duct:action:v1",
90
- issued_at: "2026-07-01T00:00:00.000Z",
91
- shell_id: "shell_test",
92
- action_id: "search",
93
- caller_type: "agent",
94
- decision: "permit",
95
- reason: "allowed",
96
- permission_source: "manifest",
97
- capture_mode: "gateway_observed",
98
- scope_of_claim: { asserts: [], does_not_assert: [] },
99
- };
100
- const signed = signTestReceipt(body);
101
- const wrongKid = {
102
- ...signed,
103
- kid: "attacker-hs512-v1",
104
- signature: "00".repeat(32),
105
- };
106
- const result = verifyReceipt(wrongKid, { hmacSecret: HMAC_SECRET });
107
- assert.equal(result.valid, false);
108
- if (!result.valid)
109
- assert.equal(result.reason, "INVALID_SIGNATURE");
110
- });
111
- });
112
- describe("P6-INV-4 deeplink replay rejects reused jti", () => {
113
- it("mint → verify ok → replay rejected; jti is non-empty", async () => {
114
- const replayStore = createDevReplayStore();
115
- const { token } = await generateDeeplinkToken({
116
- secretKey: SECRET,
117
- shellId: SHELL_ID,
118
- deeplinkId: "view_order",
119
- state: { orderId: "42" },
120
- });
121
- const first = await verifyDeeplinkToken(token, {
122
- secretKey: SECRET,
123
- expectedShellId: SHELL_ID,
124
- replayStore,
125
- });
126
- assert.equal(first.valid, true);
127
- assert.ok(first.payload);
128
- assert.notEqual(first.payload.jti, "");
129
- const second = await verifyDeeplinkToken(token, {
130
- secretKey: SECRET,
131
- expectedShellId: SHELL_ID,
132
- replayStore,
133
- });
134
- assert.equal(second.valid, false);
135
- assert.equal(second.error, "Token already used");
136
- });
137
- });
138
- describe("P6-INV-4 generateDuctToken session allowlist", () => {
139
- it("copies only auth.sessionFields scalars into delegated JWT", async () => {
140
- const { token } = await generateDuctToken({
141
- secretKey: SECRET,
142
- shellId: SHELL_ID,
143
- userSession: {
144
- userId: "u_123",
145
- jwt: "eyJhbGciOiJIUzI1NiJ9.secret",
146
- ssn: "123-45-6789",
147
- email: "user@example.com",
148
- },
149
- sessionFields: ["userId"],
150
- });
151
- const verified = await verifyDuctToken(token, {
152
- secretKey: SECRET,
153
- expectedShellId: SHELL_ID,
154
- });
155
- assert.equal(verified.valid, true);
156
- assert.deepEqual(verified.payload?.session, { userId: "u_123" });
157
- });
158
- });
159
- describe("P6-INV-4 generated embeds contain origin checks", () => {
160
- const frameworks = [
161
- {
162
- name: "react (next-app)",
163
- framework: {
164
- name: "next-app",
165
- version: "14.0.0",
166
- hasAppRouter: true,
167
- hasPagesRouter: false,
168
- packageManager: "npm",
169
- srcDir: "src",
170
- },
171
- // React embed delegates postMessage origin checks to DuctShell; shellHost must be wired.
172
- pattern: /shellHost/,
173
- },
174
- {
175
- name: "vue3",
176
- framework: {
177
- name: "vue3",
178
- version: "3.4.0",
179
- hasAppRouter: false,
180
- hasPagesRouter: false,
181
- packageManager: "npm",
182
- srcDir: "src",
183
- },
184
- pattern: /event\.origin !== shellOrigin/,
185
- },
186
- {
187
- name: "nuxt",
188
- framework: {
189
- name: "nuxt",
190
- version: "3.0.0",
191
- hasAppRouter: false,
192
- hasPagesRouter: false,
193
- packageManager: "npm",
194
- srcDir: "src",
195
- },
196
- pattern: /event\.origin !== shellOrigin/,
197
- },
198
- {
199
- name: "sveltekit",
200
- framework: {
201
- name: "sveltekit",
202
- version: "2.0.0",
203
- hasAppRouter: false,
204
- hasPagesRouter: false,
205
- packageManager: "npm",
206
- srcDir: "src",
207
- },
208
- pattern: /event\.origin !== shellHost/,
209
- },
210
- ];
211
- for (const { name, framework, pattern } of frameworks) {
212
- it(`${name} generator output includes origin guard`, () => {
213
- const code = generateShell(minimalConfig, framework);
214
- assert.match(code, pattern);
215
- });
216
- }
217
- });
@@ -1 +0,0 @@
1
- export {};