@open-conduit/sdk 7.0.0 → 7.1.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 (55) hide show
  1. package/dist/actions.d.ts +145 -0
  2. package/dist/actions.js +281 -0
  3. package/dist/actiontest.d.ts +80 -0
  4. package/dist/actiontest.js +190 -0
  5. package/dist/artifactstore.d.ts +133 -0
  6. package/dist/artifactstore.js +364 -0
  7. package/dist/backup.d.ts +99 -0
  8. package/dist/backup.js +178 -0
  9. package/dist/containertest.d.ts +71 -0
  10. package/dist/containertest.js +294 -0
  11. package/dist/errors.d.ts +28 -0
  12. package/dist/errors.js +37 -0
  13. package/dist/executor.d.ts +374 -0
  14. package/dist/executor.js +556 -0
  15. package/dist/executortest.d.ts +183 -0
  16. package/dist/executortest.js +534 -0
  17. package/dist/extension.d.ts +496 -1
  18. package/dist/extension.js +1152 -4
  19. package/dist/feed.d.ts +20 -0
  20. package/dist/feed.js +88 -0
  21. package/dist/forward.d.ts +38 -0
  22. package/dist/forward.js +163 -0
  23. package/dist/forwardca.d.ts +21 -0
  24. package/dist/forwardca.js +144 -0
  25. package/dist/hooks.d.ts +108 -0
  26. package/dist/hooks.js +13 -0
  27. package/dist/host.d.ts +166 -2
  28. package/dist/host.js +235 -2
  29. package/dist/index.d.ts +27 -3
  30. package/dist/index.js +14 -2
  31. package/dist/probe.d.ts +61 -0
  32. package/dist/probe.js +92 -0
  33. package/dist/providertest.d.ts +59 -0
  34. package/dist/providertest.js +168 -0
  35. package/dist/resources.d.ts +208 -0
  36. package/dist/resources.js +303 -0
  37. package/dist/sandbox.d.ts +84 -0
  38. package/dist/sandbox.js +85 -0
  39. package/dist/setup.d.ts +145 -0
  40. package/dist/setup.js +179 -0
  41. package/dist/setuptest.d.ts +90 -0
  42. package/dist/setuptest.js +319 -0
  43. package/dist/storetest.d.ts +64 -0
  44. package/dist/storetest.js +740 -0
  45. package/dist/telemetry.d.ts +86 -0
  46. package/dist/telemetry.js +46 -0
  47. package/dist/testing.d.ts +591 -2
  48. package/dist/testing.js +1460 -6
  49. package/dist/toolbelt.d.ts +91 -0
  50. package/dist/toolbelt.js +216 -0
  51. package/dist/tunnel.d.ts +62 -0
  52. package/dist/tunnel.js +93 -0
  53. package/dist/wire.d.ts +4060 -348
  54. package/dist/wire.js +1583 -0
  55. package/package.json +1 -1
package/dist/setup.js ADDED
@@ -0,0 +1,179 @@
1
+ // Configuration candidates (config.candidate) and setup flows (setup.run),
2
+ // as protocol/sdk serves sdk.Extension's ConfigCandidate and Setups
3
+ // (protocol/sdk/sdk.go and surfaces.go). Core owns the review and the
4
+ // apply: an extension's Work proposes, the operator decides through the
5
+ // extension's own actions, and only the operator applies. A setup flow
6
+ // runs at CLI time (`open-conduit init <type>`), driving the operator
7
+ // through the host's setup.* callbacks.
8
+ import { Code, ProtocolError } from "./errors.js";
9
+ import { t } from "./schema.js";
10
+ import { SetupAnswer, } from "./wire.js";
11
+ /** The change states core knows (extension.ChangeProposed, ChangeApproved); others (rejected, withdrawn, applied) are shown as they are. */
12
+ export const ChangeState = {
13
+ /** Waiting on the operator. */
14
+ Proposed: "proposed",
15
+ /** Approved and waiting to be applied. */
16
+ Approved: "approved",
17
+ };
18
+ /** c on the wire (protocol.FromCandidate); undefined is a Work with nothing proposed. */
19
+ export function candidateResult(c) {
20
+ if (c === undefined)
21
+ return { found: false };
22
+ const out = { found: true };
23
+ if (c.handle)
24
+ out.handle = c.handle;
25
+ if (c.baseGeneration)
26
+ out.base_generation = c.baseGeneration;
27
+ if (c.hash)
28
+ out.hash = c.hash;
29
+ if (c.changes !== undefined && c.changes.length > 0)
30
+ out.changes = c.changes.map(wireChange);
31
+ if (c.approveAll)
32
+ out.approve_all = c.approveAll;
33
+ if (c.validate)
34
+ out.validate = c.validate;
35
+ return out;
36
+ }
37
+ function wireChange(c) {
38
+ return {
39
+ id: c.id,
40
+ op: c.op,
41
+ pointer: c.pointer,
42
+ state: c.state,
43
+ ...(c.why ? { why: c.why } : {}),
44
+ ...(c.before === undefined ? {} : { before: c.before }),
45
+ ...(c.after === undefined ? {} : { after: c.after }),
46
+ ...(c.problems !== undefined && c.problems.length > 0
47
+ ? { problems: [...c.problems] }
48
+ : {}),
49
+ ...(c.approve ? { approve: c.approve } : {}),
50
+ ...(c.reject ? { reject: c.reject } : {}),
51
+ };
52
+ }
53
+ /** The candidate a config.candidate answer carries (ConfigCandidateResult.Candidate), or undefined when it has none. */
54
+ export function candidateOf(r) {
55
+ if (!r.found)
56
+ return undefined;
57
+ return {
58
+ ...(r.handle ? { handle: r.handle } : {}),
59
+ ...(r.base_generation ? { baseGeneration: r.base_generation } : {}),
60
+ ...(r.hash ? { hash: r.hash } : {}),
61
+ ...(r.changes !== undefined && r.changes.length > 0
62
+ ? {
63
+ changes: r.changes.map((c) => ({
64
+ id: c.id,
65
+ op: c.op,
66
+ pointer: c.pointer,
67
+ state: c.state,
68
+ ...(c.why ? { why: c.why } : {}),
69
+ ...(c.before === undefined ? {} : { before: c.before }),
70
+ ...(c.after === undefined ? {} : { after: c.after }),
71
+ ...(c.problems ? { problems: [...c.problems] } : {}),
72
+ ...(c.approve ? { approve: c.approve } : {}),
73
+ ...(c.reject ? { reject: c.reject } : {}),
74
+ })),
75
+ }
76
+ : {}),
77
+ ...(r.approve_all ? { approveAll: r.approve_all } : {}),
78
+ ...(r.validate ? { validate: r.validate } : {}),
79
+ };
80
+ }
81
+ /**
82
+ * Thrown by a SetupHost's prompt or choose when the session takes no
83
+ * interactive input (extension.ErrSetupNoInput): a flow run with flags
84
+ * alone, say. Fall back to a default or ask for a flag.
85
+ */
86
+ export class SetupNoInput extends Error {
87
+ constructor() {
88
+ super("setup: no interactive input");
89
+ this.name = "SetupNoInput";
90
+ }
91
+ }
92
+ /**
93
+ * A setup flow's usage error (extension.ErrSetupUsage): the arguments it
94
+ * was given don't make sense. It crosses as invalid with its message,
95
+ * which the operator reads with the flow's usage, so it must be fixed text
96
+ * with no secret in it.
97
+ */
98
+ export class SetupUsageError extends ProtocolError {
99
+ constructor(message) {
100
+ super(Code.Invalid, message);
101
+ this.name = "SetupUsageError";
102
+ }
103
+ }
104
+ const Empty = t.object({}, { open: true });
105
+ /** The SetupHost over the setup.* callbacks of run p. */
106
+ export function setupHost(host, p, signal) {
107
+ const run = p.run;
108
+ const ask = async (method, params) => {
109
+ try {
110
+ return await host.call(method, { run, ...params }, SetupAnswer, signal);
111
+ }
112
+ catch (err) {
113
+ if (err instanceof ProtocolError && err.code === Code.Unsupported)
114
+ throw new SetupNoInput();
115
+ throw err;
116
+ }
117
+ };
118
+ return {
119
+ config: p.config === undefined || p.config === ""
120
+ ? undefined
121
+ : new Uint8Array(Buffer.from(p.config, "base64")),
122
+ cwd: p.cwd,
123
+ stateDir: p.state_dir,
124
+ dryRun: p.dry_run === true,
125
+ async print(text) {
126
+ try {
127
+ await host.call("setup.print", { run, text }, Empty, signal);
128
+ }
129
+ catch {
130
+ // As the Go SDK's Printf: showing a line never fails the flow.
131
+ }
132
+ },
133
+ async prompt(question, o = {}) {
134
+ const out = await ask("setup.prompt", {
135
+ question,
136
+ ...(o.default ? { default: o.default } : {}),
137
+ ...(o.secret ? { secret: true } : {}),
138
+ });
139
+ return out.value ?? "";
140
+ },
141
+ async choose(question, options) {
142
+ const out = await ask("setup.choose", { question, options });
143
+ return out.index ?? 0;
144
+ },
145
+ async openURL(url) {
146
+ await host.call("setup.open_url", { run, url }, Empty, signal);
147
+ },
148
+ async storeSecret(name, value) {
149
+ const out = await host.call("setup.store_secret", { run, name, value }, SetupAnswer, signal);
150
+ return out.value ?? "";
151
+ },
152
+ async lookPath(name) {
153
+ try {
154
+ const out = await host.call("setup.look_path", { run, name }, SetupAnswer, signal);
155
+ return out.found ? (out.value ?? "") : undefined;
156
+ }
157
+ catch {
158
+ // As the Go SDK's LookPath: a failed lookup finds nothing.
159
+ return undefined;
160
+ }
161
+ },
162
+ async run(dir, name, args = [], s = signal) {
163
+ await host.call("setup.run_command", { run, dir, name, ...(args.length > 0 ? { args } : {}) }, Empty, s);
164
+ },
165
+ };
166
+ }
167
+ /** r on the wire (protocol.SetupRunResult). */
168
+ export function setupResult(r) {
169
+ return {
170
+ ...(r.connections !== undefined && r.connections.length > 0
171
+ ? { connections: [...r.connections] }
172
+ : {}),
173
+ ...(r.scope === undefined ? {} : { scope: r.scope }),
174
+ ...(r.summary !== undefined && r.summary.length > 0
175
+ ? { summary: [...r.summary] }
176
+ : {}),
177
+ ...(r.next !== undefined && r.next.length > 0 ? { next: [...r.next] } : {}),
178
+ };
179
+ }
@@ -0,0 +1,90 @@
1
+ import { type ConfigDiagnostic, type ConfigTraceResult } from "./wire.js";
2
+ /** The redacted stand-in for a secret reference, as the host writes it. */
3
+ export declare const Redacted = "[redacted]";
4
+ /**
5
+ * The configuration the test host's config service holds (TestHostOptions.
6
+ * config). text is the config file's text; validate answers a candidate's
7
+ * diagnostics (default: none for a JSON object, one for anything else) and
8
+ * trace a config.trace (default: the error "the test host traces no
9
+ * samples").
10
+ */
11
+ export interface TestConfig {
12
+ text: string;
13
+ /** The committed generation (default "1"). */
14
+ generation?: string;
15
+ /** The IDs of scopes from included folders. */
16
+ folders?: string[];
17
+ validate?: (text: string) => ConfigDiagnostic[];
18
+ trace?: (text: string, scope: string, sample: string | undefined) => ConfigTraceResult;
19
+ }
20
+ /** The hash the host gives config text: its SHA-256, hex. */
21
+ export declare function configHash(text: string): string;
22
+ /** text redacted, laid out as the host lays it out. */
23
+ export declare function redactConfig(text: string): string;
24
+ /**
25
+ * The test host's config service: config text behind handles, answered
26
+ * redacted, with the host's bounds on an edit. Nothing in it applies a
27
+ * configuration.
28
+ */
29
+ export declare class TestConfigService {
30
+ #private;
31
+ constructor(config: TestConfig | undefined);
32
+ /** The text behind handle, unredacted, as the host serves it to the operator alone; undefined for a handle it doesn't hold. */
33
+ text(handle: string): string | undefined;
34
+ /** Answers one config.* call as the host's config service does. */
35
+ serve(method: string, raw: unknown): unknown;
36
+ }
37
+ /**
38
+ * The operator's side of a setup run on the test host (TestHost.setup):
39
+ * what each setup.* callback answers, and what the run did. Prompts are
40
+ * answered from answers in order and choices from choices; once either
41
+ * runs out, or with noInput, the callback is refused as the host refuses
42
+ * one without interactive input (unsupported), which the flow sees as
43
+ * SetupNoInput.
44
+ */
45
+ export interface TestSetupOptions {
46
+ /** The flow's arguments. */
47
+ args?: string[];
48
+ /** The config file's text, when there is one. */
49
+ config?: string;
50
+ /** Default "/sdktest/work". */
51
+ cwd?: string;
52
+ /** Default the test host's state directory. */
53
+ stateDir?: string;
54
+ dryRun?: boolean;
55
+ answers?: string[];
56
+ choices?: number[];
57
+ noInput?: boolean;
58
+ /** Programs on the operator's PATH, by name. */
59
+ paths?: Record<string, string>;
60
+ /** Fails a command run_command runs, by its name: the message it fails with. */
61
+ failing?: Record<string, string>;
62
+ }
63
+ /** What a setup run did, as the operator saw it. */
64
+ export interface TestSetupRecord {
65
+ printed: string[];
66
+ prompts: {
67
+ question: string;
68
+ default?: string;
69
+ secret: boolean;
70
+ }[];
71
+ choices: {
72
+ question: string;
73
+ options: string[];
74
+ }[];
75
+ opened: string[];
76
+ /** Secrets stored, by name; each answers the reference "sdktest:<name>". */
77
+ secrets: Record<string, string>;
78
+ commands: {
79
+ dir: string;
80
+ name: string;
81
+ args: string[];
82
+ }[];
83
+ }
84
+ /** The test host's answers to one setup run's callbacks. */
85
+ export declare class TestSetupSession {
86
+ #private;
87
+ readonly record: TestSetupRecord;
88
+ constructor(o: TestSetupOptions);
89
+ serve(method: string, raw: unknown): unknown;
90
+ }
@@ -0,0 +1,319 @@
1
+ // The test host's config service (config.*) and setup session (setup.*),
2
+ // as the host answers them: config text behind handles, every copy the
3
+ // extension sees redacted, and a setup run's callbacks answered from a
4
+ // script and recorded. Nothing here reads the operator's config, a
5
+ // terminal, PATH or a secret store.
6
+ import { createHash } from "node:crypto";
7
+ import { Code, ProtocolError } from "./errors.js";
8
+ import { matches } from "./schema.js";
9
+ import { ConfigEditParams, ConfigHandleParams, ConfigTraceParams, SetupChooseParams, SetupCommandParams, SetupLookPathParams, SetupPrintParams, SetupPromptParams, SetupSecretParams, SetupURLParams, } from "./wire.js";
10
+ /** The redacted stand-in for a secret reference, as the host writes it. */
11
+ export const Redacted = "[redacted]";
12
+ function invalid(message) {
13
+ return new ProtocolError(Code.Invalid, message);
14
+ }
15
+ function params(schema, raw) {
16
+ const p = raw ?? {};
17
+ if (!matches(schema, p))
18
+ throw invalid("malformed params");
19
+ return p;
20
+ }
21
+ /** The hash the host gives config text: its SHA-256, hex. */
22
+ export function configHash(text) {
23
+ return createHash("sha256").update(text).digest("hex");
24
+ }
25
+ /** A JSON pointer's segments, unescaped (RFC 6901). */
26
+ function segments(pointer) {
27
+ return pointer
28
+ .slice(1)
29
+ .split("/")
30
+ .map((s) => s.replaceAll("~1", "/").replaceAll("~0", "~"));
31
+ }
32
+ function redactRef(v) {
33
+ return v === false ? false : Redacted;
34
+ }
35
+ /** v with every secret_refs value redacted, as the host redacts config text. */
36
+ function redactValue(v, refs) {
37
+ if (Array.isArray(v))
38
+ return v.map((m) => redactValue(m, false));
39
+ if (v !== null && typeof v === "object") {
40
+ const out = {};
41
+ for (const [k, m] of Object.entries(v))
42
+ out[k] = refs ? redactRef(m) : redactValue(m, k === "secret_refs");
43
+ return out;
44
+ }
45
+ return v;
46
+ }
47
+ /** A value found at pointer, redacted: the reference itself inside a secret_refs object, its values when pointer is one. */
48
+ function redactAt(pointer, v) {
49
+ if (v === undefined)
50
+ return undefined;
51
+ const parts = pointer.split("/");
52
+ if (parts.length >= 3 && parts[parts.length - 2] === "secret_refs")
53
+ return redactRef(v);
54
+ return redactValue(v, parts[parts.length - 1] === "secret_refs");
55
+ }
56
+ /** text redacted, laid out as the host lays it out. */
57
+ export function redactConfig(text) {
58
+ return JSON.stringify(redactValue(JSON.parse(text), false), null, 2);
59
+ }
60
+ /** One RFC 6902 edit to doc: the edited document and the value that was at pointer. */
61
+ function edit(doc, op, pointer, value) {
62
+ const path = segments(pointer);
63
+ const last = path.pop();
64
+ const root = structuredClone(doc);
65
+ let parent = root;
66
+ for (const seg of path) {
67
+ const next = Array.isArray(parent)
68
+ ? parent[Number(seg)]
69
+ : parent !== null && typeof parent === "object"
70
+ ? parent[seg]
71
+ : undefined;
72
+ if (next === undefined || next === null || typeof next !== "object")
73
+ throw invalid(`nothing is at ${pointer} to ${op}`);
74
+ parent = next;
75
+ }
76
+ if (Array.isArray(parent)) {
77
+ const i = last === "-" ? parent.length : Number(last);
78
+ const inRange = Number.isInteger(i) && i >= 0;
79
+ if (op === "add") {
80
+ if (!inRange || i > parent.length)
81
+ throw invalid(`${pointer} is past the end of its array`);
82
+ parent.splice(i, 0, value);
83
+ return { doc: root, before: undefined };
84
+ }
85
+ if (!inRange || i >= parent.length)
86
+ throw invalid(`nothing is at ${pointer} to ${op}`);
87
+ const before = parent[i];
88
+ if (op === "replace")
89
+ parent[i] = value;
90
+ else
91
+ parent.splice(i, 1);
92
+ return { doc: root, before };
93
+ }
94
+ if (parent === null || typeof parent !== "object")
95
+ throw invalid(`nothing is at ${pointer} to ${op}`);
96
+ const obj = parent;
97
+ const had = Object.hasOwn(obj, last);
98
+ const before = had ? obj[last] : undefined;
99
+ if (op !== "add" && !had)
100
+ throw invalid(`nothing is at ${pointer} to ${op}`);
101
+ if (op === "remove")
102
+ delete obj[last];
103
+ else
104
+ obj[last] = value;
105
+ return { doc: root, before };
106
+ }
107
+ /**
108
+ * The test host's config service: config text behind handles, answered
109
+ * redacted, with the host's bounds on an edit. Nothing in it applies a
110
+ * configuration.
111
+ */
112
+ export class TestConfigService {
113
+ #config;
114
+ #handles = new Map();
115
+ #next = 0;
116
+ constructor(config) {
117
+ this.#config = config;
118
+ }
119
+ /** The text behind handle, unredacted, as the host serves it to the operator alone; undefined for a handle it doesn't hold. */
120
+ text(handle) {
121
+ return this.#handles.get(handle);
122
+ }
123
+ #put(text) {
124
+ const h = `config-handle-${++this.#next}`;
125
+ this.#handles.set(h, text);
126
+ return h;
127
+ }
128
+ #get(handle) {
129
+ const text = this.#handles.get(handle);
130
+ if (text === undefined)
131
+ throw new ProtocolError(Code.NotFound, "the host no longer holds that configuration; read the base again");
132
+ return text;
133
+ }
134
+ /** Answers one config.* call as the host's config service does. */
135
+ serve(method, raw) {
136
+ const c = this.#config;
137
+ if (c === undefined)
138
+ throw new ProtocolError(Code.Internal, "no configuration yet");
139
+ switch (method) {
140
+ case "config.base": {
141
+ const out = {
142
+ generation: c.generation ?? "1",
143
+ hash: configHash(c.text),
144
+ handle: this.#put(c.text),
145
+ text: redactConfig(c.text),
146
+ };
147
+ if (c.folders !== undefined && c.folders.length > 0)
148
+ out.folders = [...c.folders].sort();
149
+ return out;
150
+ }
151
+ case "config.edit": {
152
+ const p = params(ConfigEditParams, raw);
153
+ // As extproc bounds one proposed edit.
154
+ if (!p.pointer.startsWith("/") ||
155
+ Buffer.byteLength(p.pointer, "utf8") > 512 ||
156
+ /[\r\n]/.test(p.pointer))
157
+ throw invalid("pointer is a JSON pointer of at most 512 bytes");
158
+ switch (p.op) {
159
+ case "add":
160
+ case "replace":
161
+ if (p.value === undefined ||
162
+ Buffer.byteLength(JSON.stringify(p.value), "utf8") > 64 << 10)
163
+ throw invalid(`${p.op} needs a JSON value of at most 64 KiB`);
164
+ break;
165
+ case "remove":
166
+ if (p.value !== undefined)
167
+ throw invalid("remove takes no value");
168
+ break;
169
+ default:
170
+ throw invalid("op is add, replace or remove");
171
+ }
172
+ const text = this.#get(p.handle);
173
+ let doc;
174
+ try {
175
+ doc = JSON.parse(text);
176
+ }
177
+ catch {
178
+ throw invalid("the config is not a JSON object");
179
+ }
180
+ const e = edit(doc, p.op, p.pointer, p.value);
181
+ const next = JSON.stringify(e.doc, null, 2);
182
+ const out = {
183
+ handle: this.#put(next),
184
+ text: redactConfig(next),
185
+ };
186
+ const before = redactAt(p.pointer, e.before);
187
+ if (before !== undefined)
188
+ out.before = before;
189
+ return out;
190
+ }
191
+ case "config.validate": {
192
+ const p = params(ConfigHandleParams, raw);
193
+ const text = this.#get(p.handle);
194
+ const diags = c.validate
195
+ ? c.validate(text)
196
+ : objectText(text)
197
+ ? []
198
+ : [
199
+ {
200
+ path: "",
201
+ code: "invalid",
202
+ message: "the configuration is not valid JSON",
203
+ },
204
+ ];
205
+ const out = {};
206
+ if (diags.length === 0)
207
+ out.hash = configHash(text);
208
+ else
209
+ out.diagnostics = diags;
210
+ return out;
211
+ }
212
+ case "config.trace": {
213
+ const p = params(ConfigTraceParams, raw);
214
+ if (p.scope === "" ||
215
+ p.scope.length > 200 ||
216
+ (p.sample ?? "").length > 200)
217
+ throw invalid("a scope's ID, and a sample's ID from the list a trace without one returns");
218
+ const text = this.#get(p.handle);
219
+ return c.trace
220
+ ? c.trace(text, p.scope, p.sample)
221
+ : { error: "the test host traces no samples" };
222
+ }
223
+ }
224
+ throw new ProtocolError(Code.Unsupported, method);
225
+ }
226
+ }
227
+ function objectText(text) {
228
+ try {
229
+ const v = JSON.parse(text);
230
+ return v !== null && typeof v === "object" && !Array.isArray(v);
231
+ }
232
+ catch {
233
+ return false;
234
+ }
235
+ }
236
+ /** The test host's answers to one setup run's callbacks. */
237
+ export class TestSetupSession {
238
+ record = {
239
+ printed: [],
240
+ prompts: [],
241
+ choices: [],
242
+ opened: [],
243
+ secrets: {},
244
+ commands: [],
245
+ };
246
+ #o;
247
+ #answer = 0;
248
+ #choice = 0;
249
+ constructor(o) {
250
+ this.#o = o;
251
+ }
252
+ serve(method, raw) {
253
+ const noInput = () => new ProtocolError(Code.Unsupported, "no interactive input");
254
+ switch (method) {
255
+ case "setup.print": {
256
+ const p = params(SetupPrintParams, raw);
257
+ this.record.printed.push(p.text);
258
+ return {};
259
+ }
260
+ case "setup.prompt": {
261
+ const p = params(SetupPromptParams, raw);
262
+ this.record.prompts.push({
263
+ question: p.question,
264
+ ...(p.default ? { default: p.default } : {}),
265
+ secret: p.secret === true,
266
+ });
267
+ const answers = this.#o.answers ?? [];
268
+ if (this.#o.noInput || this.#answer >= answers.length)
269
+ throw noInput();
270
+ const v = answers[this.#answer++];
271
+ return { value: v === "" ? (p.default ?? "") : v };
272
+ }
273
+ case "setup.choose": {
274
+ const p = params(SetupChooseParams, raw);
275
+ this.record.choices.push({
276
+ question: p.question,
277
+ options: [...p.options],
278
+ });
279
+ const choices = this.#o.choices ?? [];
280
+ if (this.#o.noInput || this.#choice >= choices.length)
281
+ throw noInput();
282
+ const i = choices[this.#choice++];
283
+ if (i < 0 || i >= p.options.length)
284
+ throw invalid("no such option");
285
+ return { index: i };
286
+ }
287
+ case "setup.open_url": {
288
+ const p = params(SetupURLParams, raw);
289
+ this.record.opened.push(p.url);
290
+ return {};
291
+ }
292
+ case "setup.store_secret": {
293
+ const p = params(SetupSecretParams, raw);
294
+ if (p.name === "")
295
+ throw invalid("a secret needs a name");
296
+ this.record.secrets[p.name] = p.value;
297
+ return { value: `sdktest:${p.name}` };
298
+ }
299
+ case "setup.look_path": {
300
+ const p = params(SetupLookPathParams, raw);
301
+ const path = this.#o.paths?.[p.name];
302
+ return path === undefined ? {} : { value: path, found: true };
303
+ }
304
+ case "setup.run_command": {
305
+ const p = params(SetupCommandParams, raw);
306
+ this.record.commands.push({
307
+ dir: p.dir,
308
+ name: p.name,
309
+ args: [...(p.args ?? [])],
310
+ });
311
+ const failure = this.#o.failing?.[p.name];
312
+ if (failure !== undefined)
313
+ throw new ProtocolError(Code.Internal, failure);
314
+ return {};
315
+ }
316
+ }
317
+ throw new ProtocolError(Code.Unsupported, method);
318
+ }
319
+ }
@@ -0,0 +1,64 @@
1
+ import { type ArtifactBackend, type StoredArtifactRef, type Ownership, type StoredArtifact } from "./artifactstore.js";
2
+ import type { TestBackupDestination } from "./testing.js";
3
+ /** A fresh, empty target of the destination each call: two calls name targets that share nothing (conformance.BackupHarness). */
4
+ export type BackupTargets = () => TestBackupDestination | Promise<TestBackupDestination>;
5
+ /** One guarantee of a backup destination (conformance.BackupCase). */
6
+ export interface BackupCase {
7
+ name: string;
8
+ check: (target: BackupTargets) => Promise<void>;
9
+ }
10
+ /** The shared backup destination cases (conformance.BackupCases). */
11
+ export declare const backupCases: BackupCase[];
12
+ /** Runs every backup destination case, rejecting with the first a destination breaks (conformance.RunBackup). */
13
+ export declare function checkBackupDestination(target: BackupTargets): Promise<void>;
14
+ /** Content being written to a store over the wire. */
15
+ export interface TestArtifactWriter {
16
+ write(chunk: Uint8Array | string): Promise<void>;
17
+ /** Publishes the content, refusing a ref that doesn't match what was written (ArtifactError Corrupt), as the host does. */
18
+ commit(): Promise<StoredArtifactRef>;
19
+ /** Abandons the content. */
20
+ close(): Promise<void>;
21
+ }
22
+ /** A store opened at one location over its own connection, as the host's artifactstore.Command opens one. */
23
+ export interface TestArtifactStore {
24
+ /** What the provider said at initialize: whether another host can reach the store, or undefined for no claim. */
25
+ readonly shared: boolean | undefined;
26
+ create(mediaType: string): Promise<TestArtifactWriter>;
27
+ /** Reads ref's content to its end, refusing content that doesn't match its size or digest (ArtifactError Corrupt), as the host does. */
28
+ read(ref: StoredArtifactRef): Promise<Uint8Array>;
29
+ delete(ref: StoredArtifactRef): Promise<void>;
30
+ list(after: string, limit: number): Promise<StoredArtifact[]>;
31
+ /** Imports body as ref, refusing a source that doesn't match ref (ArtifactError Corrupt) before the provider would publish it, as the host does. */
32
+ import(ref: StoredArtifactRef, body: Uint8Array | string): Promise<void>;
33
+ claim(o: Ownership): Promise<void>;
34
+ checkOwner(installation: string): Promise<void>;
35
+ /** Ends the connection; the provider closes the store. */
36
+ close(): Promise<void>;
37
+ }
38
+ /** An artifact provider served in this process, reached as the host reaches one. */
39
+ export interface TestArtifactProvider {
40
+ open(location: string): Promise<TestArtifactStore>;
41
+ }
42
+ /**
43
+ * Serves backend as an artifact provider in this process: each open starts
44
+ * a connection of its own, as the host starts a provider process, and
45
+ * initializes it at the location.
46
+ */
47
+ export declare function testArtifactProvider(backend: ArtifactBackend): TestArtifactProvider;
48
+ /** A provider to check, and where its stores go (conformance.ArtifactHarness). */
49
+ export interface ArtifactFixture {
50
+ provider: TestArtifactProvider;
51
+ /** A fresh, empty location each call. */
52
+ location: () => string | Promise<string>;
53
+ /** A location inside location, for a backend whose locations nest (a prefix, a directory); leave it out when they don't. */
54
+ nested?: (location: string) => string;
55
+ }
56
+ /** One guarantee of an artifact store (conformance.ArtifactCase). */
57
+ export interface ArtifactCase {
58
+ name: string;
59
+ check: (f: ArtifactFixture) => Promise<void>;
60
+ }
61
+ /** The shared artifact store cases this test client can run (of conformance.ArtifactCases). */
62
+ export declare const artifactCases: ArtifactCase[];
63
+ /** Runs every artifact case, rejecting with the first a store breaks (conformance.RunArtifacts). */
64
+ export declare function checkArtifactStore(f: ArtifactFixture): Promise<void>;