@halonicjs/testing 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/README.md +1 -1
- package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
- package/dist/adapters/http-kit/src/address-checking.js +1 -0
- package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +3 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
- package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
- package/dist/adapters/integration-kit/src/declaration.js +4 -3
- package/dist/adapters/integration-kit/src/host.d.ts +7 -1
- package/dist/adapters/integration-kit/src/host.js +1 -0
- package/dist/adapters/integration-kit/src/index.d.ts +5 -2
- package/dist/adapters/integration-kit/src/index.js +2 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
- package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
- package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
- package/dist/adapters/integration-kit/src/limited-http.js +53 -10
- package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
- package/dist/adapters/integration-kit/src/loader.js +36 -21
- package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
- package/dist/adapters/integration-kit/src/own-request.js +1 -1
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
- package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
- package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
- package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
- package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
- package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
- package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/blocked-sites.d.ts +57 -0
- package/dist/core/events/src/blocked-sites.js +89 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +8 -2
- package/dist/core/events/src/index.js +5 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +131 -10
- package/dist/core/events/src/run-event.d.ts +120 -11
- package/dist/core/events/src/run-reads.d.ts +25 -0
- package/dist/core/events/src/run-reads.js +44 -0
- package/dist/core/events/src/run-sends.d.ts +47 -0
- package/dist/core/events/src/run-sends.js +68 -0
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +8 -1
- package/dist/core/events/src/timeline-entry.js +1 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +9 -6
- package/dist/core/format/src/index.js +7 -3
- package/dist/core/format/src/integration/index.d.ts +3 -2
- package/dist/core/format/src/integration/index.js +2 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +5 -2
- package/dist/core/format/src/kinds/connector/is-local.js +1 -1
- package/dist/core/format/src/kinds/connector/kind.js +122 -2
- package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
- package/dist/core/format/src/kinds/connector/schema.js +71 -2
- package/dist/core/format/src/kinds/deployments/kind.js +25 -1
- package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
- package/dist/core/format/src/kinds/deployments/schema.js +52 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
- package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
- package/dist/core/format/src/kinds/integration/host-key.js +8 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
- package/dist/core/format/src/kinds/integration/kind.js +49 -12
- package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
- package/dist/core/format/src/kinds/integration/policy.js +61 -2
- package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
- package/dist/core/format/src/kinds/integration/schema.js +133 -7
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +24 -6
- package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
- package/dist/core/format/src/kinds/plugin/schema.js +26 -6
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
- package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.js +38 -1
- package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
- package/dist/core/format/src/kinds/routine/schema.js +42 -14
- package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
- package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
- package/dist/core/format/src/kinds/workflow/schema.js +1 -1
- package/dist/core/format/src/kinds/workspace/kind.js +1 -1
- package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
- package/dist/core/format/src/kinds/workspace/schema.js +6 -5
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +12 -8
- package/dist/core/format/src/shared/fields.js +48 -19
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
- package/dist/core/ports/src/agent-runs-not-available.js +25 -0
- package/dist/core/ports/src/blob-store.d.ts +12 -0
- package/dist/core/ports/src/blob-store.js +22 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-client.d.ts +48 -4
- package/dist/core/ports/src/connector-client.js +17 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +36 -5
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
- package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
- package/dist/core/ports/src/harness-sign-in-command.js +31 -0
- package/dist/core/ports/src/harness.d.ts +79 -15
- package/dist/core/ports/src/harness.js +1 -1
- package/dist/core/ports/src/host-settings-store.d.ts +116 -0
- package/dist/core/ports/src/host-settings-store.js +106 -0
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +32 -13
- package/dist/core/ports/src/index.js +28 -8
- package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
- package/dist/core/ports/src/instruction-trust-store.js +43 -0
- package/dist/core/ports/src/integration.d.ts +71 -7
- package/dist/core/ports/src/integration.js +22 -4
- package/dist/core/ports/src/llm-provider.d.ts +39 -6
- package/dist/core/ports/src/llm-provider.js +46 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/password-hasher.d.ts +36 -20
- package/dist/core/ports/src/port-versions.d.ts +13 -6
- package/dist/core/ports/src/port-versions.js +14 -0
- package/dist/core/ports/src/program-probe.d.ts +25 -2
- package/dist/core/ports/src/program-probe.js +1 -1
- package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
- package/dist/core/ports/src/provider-default-base-url.js +18 -0
- package/dist/core/ports/src/record-store.d.ts +17 -0
- package/dist/core/ports/src/record-store.js +70 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +44 -7
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
- package/dist/core/ports/src/run-target-not-found.js +41 -0
- package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
- package/dist/core/ports/src/sandbox-setting-store.js +33 -0
- package/dist/core/ports/src/sandbox.d.ts +149 -13
- package/dist/core/ports/src/sandbox.js +52 -2
- package/dist/core/ports/src/secrets.d.ts +105 -1
- package/dist/core/ports/src/secrets.js +75 -2
- package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
- package/dist/core/ports/src/tool-approval-store.js +59 -0
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs-status.d.ts +8 -0
- package/dist/core/ports/src/vcs-status.js +90 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/amount.d.ts +13 -0
- package/dist/core/std/src/amount.js +22 -0
- package/dist/core/std/src/hidden-characters.d.ts +28 -0
- package/dist/core/std/src/hidden-characters.js +72 -0
- package/dist/core/std/src/index.d.ts +7 -0
- package/dist/core/std/src/index.js +7 -0
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
- package/dist/core/std/src/public-suffixes.generated.js +10428 -0
- package/dist/core/std/src/registrable-domain.d.ts +10 -0
- package/dist/core/std/src/registrable-domain.js +62 -0
- package/dist/core/std/src/secret-variable-name.d.ts +12 -0
- package/dist/core/std/src/secret-variable-name.js +34 -0
- package/dist/core/std/src/site-name.d.ts +35 -0
- package/dist/core/std/src/site-name.js +111 -0
- package/dist/core/std/src/url-host.d.ts +35 -0
- package/dist/core/std/src/url-host.js +170 -0
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/dist/testing/integration/src/load.js +3 -1
- package/package.json +9 -2
|
@@ -17,6 +17,8 @@ export function applyEditToData(data, edit) {
|
|
|
17
17
|
return deleteData(data, edit.path);
|
|
18
18
|
case "insert":
|
|
19
19
|
return insertData(data, edit.path, edit.value);
|
|
20
|
+
case "rename":
|
|
21
|
+
return renameData(data, edit.path, edit.to);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
@@ -112,11 +114,15 @@ function addKeyAfter(record, key, value, after) {
|
|
|
112
114
|
const previous = after === null ? -1 : entries.findIndex(([name]) => name === after);
|
|
113
115
|
const at = after !== null && previous === -1 ? entries.length : previous + 1;
|
|
114
116
|
entries.splice(at, 0, [key, value]);
|
|
115
|
-
|
|
117
|
+
replaceEntries(record, entries);
|
|
118
|
+
}
|
|
119
|
+
/** Gives `record` exactly `entries`, in their order. */
|
|
120
|
+
function replaceEntries(record, entries) {
|
|
121
|
+
for (const name of Object.keys(record)) {
|
|
116
122
|
delete record[name];
|
|
117
123
|
}
|
|
118
|
-
for (const [name,
|
|
119
|
-
setKey(record, name,
|
|
124
|
+
for (const [name, value] of entries) {
|
|
125
|
+
setKey(record, name, value);
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
128
|
function deleteData(data, path) {
|
|
@@ -180,6 +186,56 @@ function insertData(data, path, value) {
|
|
|
180
186
|
list.splice(index, 0, deepClone(value));
|
|
181
187
|
return ok(copy);
|
|
182
188
|
}
|
|
189
|
+
function renameData(data, path, to) {
|
|
190
|
+
const key = path[path.length - 1];
|
|
191
|
+
if (typeof key !== "string") {
|
|
192
|
+
return err("rename needs a path that ends in a map key.");
|
|
193
|
+
}
|
|
194
|
+
if (typeof to !== "string") {
|
|
195
|
+
return err(`rename needs a text key to rename to, not ${describeKind(to)}.`);
|
|
196
|
+
}
|
|
197
|
+
const mapPath = path.slice(0, -1);
|
|
198
|
+
const copy = deepClone(data);
|
|
199
|
+
let map = copy;
|
|
200
|
+
for (let depth = 0; depth < mapPath.length; depth++) {
|
|
201
|
+
if (isMissing(map)) {
|
|
202
|
+
return err(nothingToRename(path));
|
|
203
|
+
}
|
|
204
|
+
const container = asContainer(map, path, depth);
|
|
205
|
+
if (!container.ok) {
|
|
206
|
+
return container;
|
|
207
|
+
}
|
|
208
|
+
const child = readChild(container.value, path, depth);
|
|
209
|
+
if (!child.ok) {
|
|
210
|
+
return child;
|
|
211
|
+
}
|
|
212
|
+
map = child.value;
|
|
213
|
+
}
|
|
214
|
+
if (isMissing(map)) {
|
|
215
|
+
return err(nothingToRename(path));
|
|
216
|
+
}
|
|
217
|
+
if (Array.isArray(map)) {
|
|
218
|
+
return err(`${describePath(mapPath)} is a list; rename needs a path that ends in a map key.`);
|
|
219
|
+
}
|
|
220
|
+
if (!isRecord(map)) {
|
|
221
|
+
return err(`${describePath(mapPath)} holds ${describeKind(map)}, not a map.`);
|
|
222
|
+
}
|
|
223
|
+
if (!Object.hasOwn(map, key)) {
|
|
224
|
+
return err(nothingToRename(path));
|
|
225
|
+
}
|
|
226
|
+
if (to === key) {
|
|
227
|
+
return ok(copy);
|
|
228
|
+
}
|
|
229
|
+
if (Object.hasOwn(map, to)) {
|
|
230
|
+
return err(`${describePath([...mapPath, to])} is already a key; rename doesn't merge keys.`);
|
|
231
|
+
}
|
|
232
|
+
// Every key is added again, so the renamed one keeps its place (see `addKeyAfter`).
|
|
233
|
+
replaceEntries(map, Object.entries(map).map(([name, value]) => [name === key ? to : name, value]));
|
|
234
|
+
return ok(copy);
|
|
235
|
+
}
|
|
236
|
+
function nothingToRename(path) {
|
|
237
|
+
return `There is no key at ${describePath(path)} to rename.`;
|
|
238
|
+
}
|
|
183
239
|
/** The value at `path[depth]` inside a container; an index past the end is a problem. */
|
|
184
240
|
function readChild(container, path, depth) {
|
|
185
241
|
const key = path[depth];
|
|
@@ -267,6 +323,9 @@ function checkValueAt(value, path, open, maxDepth) {
|
|
|
267
323
|
open.delete(value);
|
|
268
324
|
return undefined;
|
|
269
325
|
}
|
|
326
|
+
function isRecord(value) {
|
|
327
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
328
|
+
}
|
|
270
329
|
function isPlainRecord(value) {
|
|
271
330
|
const prototype = Object.getPrototypeOf(value);
|
|
272
331
|
return prototype === Object.prototype || prototype === null;
|
|
@@ -43,5 +43,12 @@ export interface YamlEdited {
|
|
|
43
43
|
* { kind: "set", path: ["name"], value: "Invoices" },
|
|
44
44
|
* ]);
|
|
45
45
|
* // { ok: true, value: { text: "name: Invoices # shown in the list\n", layout: "kept" } }
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // A rename changes only the key; the value and the comments inside it stay.
|
|
49
|
+
* const renamed = editYaml("states:\n write: # the first draft\n agent: writer\n", [
|
|
50
|
+
* { kind: "rename", path: ["states", "write"], to: "draft" },
|
|
51
|
+
* ]);
|
|
52
|
+
* // { ok: true, value: { text: "states:\n draft: # the first draft\n agent: writer\n", layout: "kept" } }
|
|
46
53
|
*/
|
|
47
54
|
export declare function editYaml(text: string, edits: readonly YamlEdit[], limits?: YamlLimits): Result<YamlEdited, YamlProblem | YamlEditProblem>;
|
|
@@ -24,6 +24,13 @@ import { writeYamlFile } from "./write.js";
|
|
|
24
24
|
* { kind: "set", path: ["name"], value: "Invoices" },
|
|
25
25
|
* ]);
|
|
26
26
|
* // { ok: true, value: { text: "name: Invoices # shown in the list\n", layout: "kept" } }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // A rename changes only the key; the value and the comments inside it stay.
|
|
30
|
+
* const renamed = editYaml("states:\n write: # the first draft\n agent: writer\n", [
|
|
31
|
+
* { kind: "rename", path: ["states", "write"], to: "draft" },
|
|
32
|
+
* ]);
|
|
33
|
+
* // { ok: true, value: { text: "states:\n draft: # the first draft\n agent: writer\n", layout: "kept" } }
|
|
27
34
|
*/
|
|
28
35
|
export function editYaml(text, edits, limits = defaultYamlLimits) {
|
|
29
36
|
const read = readYaml(text, limits);
|
|
@@ -45,7 +52,9 @@ function worseLayout(first, second) {
|
|
|
45
52
|
return layoutOrder.indexOf(first) >= layoutOrder.indexOf(second) ? first : second;
|
|
46
53
|
}
|
|
47
54
|
function applyEdit(before, edit, limits) {
|
|
48
|
-
const valueProblem = edit.kind === "
|
|
55
|
+
const valueProblem = edit.kind === "set" || edit.kind === "insert"
|
|
56
|
+
? checkValue(edit.value, limits.maxDepth)
|
|
57
|
+
: undefined;
|
|
49
58
|
if (valueProblem !== undefined) {
|
|
50
59
|
return err(valueProblem);
|
|
51
60
|
}
|
|
@@ -90,6 +99,9 @@ function renderWithDocument(text, edit, expected) {
|
|
|
90
99
|
if (edit.kind === "insert") {
|
|
91
100
|
return insertIntoDocument(document, edit) ? render(text, document) : undefined;
|
|
92
101
|
}
|
|
102
|
+
if (edit.kind === "rename") {
|
|
103
|
+
return renameInDocument(document, edit) ? render(text, document) : undefined;
|
|
104
|
+
}
|
|
93
105
|
return setInDocument(text, document, edit, expected);
|
|
94
106
|
}
|
|
95
107
|
function insertIntoDocument(document, edit) {
|
|
@@ -101,6 +113,20 @@ function insertIntoDocument(document, edit) {
|
|
|
101
113
|
list.items.splice(path[path.length - 1], 0, document.createNode(edit.value));
|
|
102
114
|
return true;
|
|
103
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Changes the value of the key's scalar node rather than putting a new node in
|
|
118
|
+
* its place, so the comments the library hangs on the key stay with it.
|
|
119
|
+
*/
|
|
120
|
+
function renameInDocument(document, edit) {
|
|
121
|
+
const map = parentMap(document, edit.path);
|
|
122
|
+
const name = edit.path[edit.path.length - 1];
|
|
123
|
+
const key = map?.items.find((pair) => isScalar(pair.key) && String(pair.key.value) === name)?.key;
|
|
124
|
+
if (!isScalar(key)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
key.value = edit.to;
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
104
130
|
function setInDocument(text, document, edit, expected) {
|
|
105
131
|
const { path } = edit;
|
|
106
132
|
const existing = document.getIn(path, true);
|
|
@@ -130,8 +156,8 @@ function setInDocument(text, document, edit, expected) {
|
|
|
130
156
|
* isn't there leaves it at the end.
|
|
131
157
|
*/
|
|
132
158
|
function moveNewPair(document, path, after) {
|
|
133
|
-
const map =
|
|
134
|
-
if (
|
|
159
|
+
const map = parentMap(document, path);
|
|
160
|
+
if (map === undefined) {
|
|
135
161
|
return;
|
|
136
162
|
}
|
|
137
163
|
const added = map.items.pop();
|
|
@@ -149,6 +175,11 @@ function moveNewPair(document, path, after) {
|
|
|
149
175
|
}
|
|
150
176
|
map.items.splice(previous + 1, 0, added);
|
|
151
177
|
}
|
|
178
|
+
/** The map that holds the last key of `path`, or `undefined` when that isn't a map. */
|
|
179
|
+
function parentMap(document, path) {
|
|
180
|
+
const map = path.length === 1 ? document.contents : document.getIn(path.slice(0, -1), true);
|
|
181
|
+
return isMap(map) ? map : undefined;
|
|
182
|
+
}
|
|
152
183
|
/** Replace the whole document, carrying over the comment at the top of the file. */
|
|
153
184
|
function replaceContents(document, value) {
|
|
154
185
|
const top = topCommentNode(document.contents);
|
|
@@ -35,6 +35,12 @@ export declare function replaceFlow(parsed: Parsed, node: YAMLMap | YAMLSeq, val
|
|
|
35
35
|
export declare function replaceValue(parsed: Parsed, path: YamlPath, value: unknown): string | undefined;
|
|
36
36
|
/** Replaces a one-line scalar's characters only, so a trailing comment and the quote style stay. */
|
|
37
37
|
export declare function replaceScalar(parsed: Parsed, node: Node, value: unknown): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Renames the map key at `path` by replacing its scalar's characters only, so
|
|
40
|
+
* its value, the comments around it and its place in the map stay. A quoted
|
|
41
|
+
* key stays quoted the same way; a plain one gets quotes when `to` needs them.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renameKey(parsed: Parsed, path: YamlPath, to: string): string | undefined;
|
|
38
44
|
/**
|
|
39
45
|
* Adds `key: value` to the block map at `mapPath`: after its last entry, or
|
|
40
46
|
* right after the entry `after` names, or first (above the comments over the
|
|
@@ -161,6 +161,16 @@ export function replaceScalar(parsed, node, value) {
|
|
|
161
161
|
}
|
|
162
162
|
return parsed.text.slice(0, start) + rendered + parsed.text.slice(end);
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Renames the map key at `path` by replacing its scalar's characters only, so
|
|
166
|
+
* its value, the comments around it and its place in the map stay. A quoted
|
|
167
|
+
* key stays quoted the same way; a plain one gets quotes when `to` needs them.
|
|
168
|
+
*/
|
|
169
|
+
export function renameKey(parsed, path, to) {
|
|
170
|
+
const map = nodeAt(parsed, path.slice(0, -1));
|
|
171
|
+
const key = isMap(map) ? pairOf(map, path[path.length - 1])?.key : undefined;
|
|
172
|
+
return isScalar(key) ? replaceScalar(parsed, key, to) : undefined;
|
|
173
|
+
}
|
|
164
174
|
/**
|
|
165
175
|
* Adds `key: value` to the block map at `mapPath`: after its last entry, or
|
|
166
176
|
* right after the entry `after` names, or first (above the comments over the
|
|
@@ -2,7 +2,7 @@ import { deepEqual } from "../../std/src/index.js";
|
|
|
2
2
|
import { isMap, isScalar, isSeq } from "yaml";
|
|
3
3
|
import { applyEditToData } from "./edit-data.js";
|
|
4
4
|
import { lineEndingOf } from "./edit-text.js";
|
|
5
|
-
import { addPair, deleteEntry, flowAncestor, insertItem, isFilledFlow, nodeAt, parse, replaceFlow, replaceScalar, replaceValue, } from "./splice-node.js";
|
|
5
|
+
import { addPair, deleteEntry, flowAncestor, insertItem, isFilledFlow, nodeAt, parse, renameKey, replaceFlow, replaceScalar, replaceValue, } from "./splice-node.js";
|
|
6
6
|
/**
|
|
7
7
|
* Applies one edit by changing only the text of what it touches, so comments,
|
|
8
8
|
* key order, quoting and blank lines elsewhere stay byte for byte. Expects an
|
|
@@ -40,12 +40,14 @@ function spliceLines(text, edit) {
|
|
|
40
40
|
return nodeAt(parsed, edit.path) === undefined ? text : deleteEntry(parsed, edit.path);
|
|
41
41
|
case "insert":
|
|
42
42
|
return insertItem(parsed, edit.path.slice(0, -1), edit.path[edit.path.length - 1], edit.value);
|
|
43
|
+
case "rename":
|
|
44
|
+
return renameKey(parsed, edit.path, edit.to);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* An edit inside the flow collection at `edit.path.slice(0, length)`. A set
|
|
47
|
-
* of one scalar changes only
|
|
48
|
-
* anything else writes the whole collection again.
|
|
49
|
+
* of one scalar, or a rename, changes only that scalar's characters when that
|
|
50
|
+
* reads back right; anything else writes the whole collection again.
|
|
49
51
|
*/
|
|
50
52
|
function spliceInFlow(parsed, edit, length) {
|
|
51
53
|
const flowPath = edit.path.slice(0, length);
|
|
@@ -60,16 +62,24 @@ function spliceInFlow(parsed, edit, length) {
|
|
|
60
62
|
if (!value.ok) {
|
|
61
63
|
return undefined;
|
|
62
64
|
}
|
|
65
|
+
// In flow style `,` and brackets end a plain text, so check the result.
|
|
66
|
+
const spliced = spliceOneScalar(parsed, edit);
|
|
67
|
+
const after = spliced === undefined ? undefined : nodeAt(parse(spliced), flowPath);
|
|
68
|
+
if (after != null && deepEqual(after.toJS(parsed.document), value.value)) {
|
|
69
|
+
return spliced;
|
|
70
|
+
}
|
|
71
|
+
return replaceFlow(parsed, flow, value.value);
|
|
72
|
+
}
|
|
73
|
+
/** The edit as a change of one scalar's characters: a key's for a rename, a value's for a set. */
|
|
74
|
+
function spliceOneScalar(parsed, edit) {
|
|
75
|
+
if (edit.kind === "rename") {
|
|
76
|
+
return renameKey(parsed, edit.path, edit.to);
|
|
77
|
+
}
|
|
63
78
|
const target = nodeAt(parsed, edit.path);
|
|
64
79
|
if (edit.kind === "set" && isScalar(target) && !isCollectionValue(edit.value)) {
|
|
65
|
-
|
|
66
|
-
const spliced = replaceScalar(parsed, target, edit.value);
|
|
67
|
-
const after = spliced === undefined ? undefined : nodeAt(parse(spliced), flowPath);
|
|
68
|
-
if (after != null && deepEqual(after.toJS(parsed.document), value.value)) {
|
|
69
|
-
return spliced;
|
|
70
|
-
}
|
|
80
|
+
return replaceScalar(parsed, target, edit.value);
|
|
71
81
|
}
|
|
72
|
-
return
|
|
82
|
+
return undefined;
|
|
73
83
|
}
|
|
74
84
|
/** Sets an existing value, or adds the first missing key with the maps under it. */
|
|
75
85
|
function spliceSet(parsed, path, value, after) {
|
|
@@ -2,9 +2,11 @@ import { type ConformanceSubject, type ToolCase } from "./run.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* The sheet passes its schema, and the integration is exactly what it says:
|
|
4
4
|
* kit version, name, version, and each tool's text, arguments, `risk` and
|
|
5
|
-
* `untrusted`, as the kit's loader checks them.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* `untrusted`, as the kit's loader checks them. On top of the loader, the
|
|
6
|
+
* sheet lists the tools in the code's order and every argument has a
|
|
7
|
+
* description (see {@link checkSheetShowsEverything}). Every case calls a
|
|
8
|
+
* declared tool, and every recording is a valid `halonic.recording/1` file
|
|
9
|
+
* of this integration.
|
|
8
10
|
*/
|
|
9
11
|
export declare function checkDeclaration(subject: ConformanceSubject): void;
|
|
10
12
|
/**
|
|
@@ -12,15 +12,18 @@ import { scanIntegrationSource } from "./source-scan.js";
|
|
|
12
12
|
/**
|
|
13
13
|
* The sheet passes its schema, and the integration is exactly what it says:
|
|
14
14
|
* kit version, name, version, and each tool's text, arguments, `risk` and
|
|
15
|
-
* `untrusted`, as the kit's loader checks them.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* `untrusted`, as the kit's loader checks them. On top of the loader, the
|
|
16
|
+
* sheet lists the tools in the code's order and every argument has a
|
|
17
|
+
* description (see {@link checkSheetShowsEverything}). Every case calls a
|
|
18
|
+
* declared tool, and every recording is a valid `halonic.recording/1` file
|
|
19
|
+
* of this integration.
|
|
18
20
|
*/
|
|
19
21
|
export function checkDeclaration(subject) {
|
|
20
22
|
const sheet = sheetOf(subject);
|
|
21
23
|
const problems = declarationProblems(sheet, subject.integration);
|
|
22
24
|
if (problems.length > 0)
|
|
23
25
|
fail(problems.map((problem) => problem.message).join("\n"));
|
|
26
|
+
checkSheetShowsEverything(sheet, subject.integration);
|
|
24
27
|
checkRecordings(subject);
|
|
25
28
|
const tools = new Set(sheet.tools.map((tool) => tool.name));
|
|
26
29
|
for (const toolCase of subject.cases) {
|
|
@@ -30,6 +33,31 @@ export function checkDeclaration(subject) {
|
|
|
30
33
|
fail(`a case replays the scenario "${toolCase.scenario}", which has no recording`);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* What the loader leaves out and a reviewer used to compare by hand
|
|
38
|
+
* (HAL-14082): the sheet lists the tools in the order the code offers them,
|
|
39
|
+
* and every argument the code takes has a description. An argument without
|
|
40
|
+
* one can't be on the sheet, so the user would approve a tool without seeing
|
|
41
|
+
* it. Runs after `declarationProblems`, so both sides name the same tools.
|
|
42
|
+
*/
|
|
43
|
+
function checkSheetShowsEverything(sheet, integration) {
|
|
44
|
+
const sheetOrder = sheet.tools.map((tool) => tool.name);
|
|
45
|
+
const codeOrder = integration.tools.map((tool) => tool.name);
|
|
46
|
+
if (sheetOrder.join("\n") !== codeOrder.join("\n")) {
|
|
47
|
+
fail(`the sheet lists the tools as ${sheetOrder.join(", ")}; the code offers them as ${codeOrder.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
for (const tool of integration.tools) {
|
|
50
|
+
const properties = tool.parameters["properties"];
|
|
51
|
+
if (typeof properties !== "object" || properties === null)
|
|
52
|
+
continue;
|
|
53
|
+
for (const [argument, schema] of Object.entries(properties)) {
|
|
54
|
+
const description = schema?.description;
|
|
55
|
+
if (typeof description !== "string" || description.trim() === "") {
|
|
56
|
+
fail(`"${tool.name}" takes "${argument}" without a description, so the sheet can't show it`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
33
61
|
/** Every recording passes the format's schema and belongs to this integration. */
|
|
34
62
|
function checkRecordings(subject) {
|
|
35
63
|
for (const [index, recording] of subject.recordings.entries()) {
|
|
@@ -16,7 +16,9 @@ export function loadSubject(subject, transport, tokens = emptyTokens) {
|
|
|
16
16
|
// The canary store answers by name, so each secret is picked as itself.
|
|
17
17
|
secretNames: Object.fromEntries(Object.keys(sheet.secrets).map((name) => [name, name])),
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
// A replay answers from the recording and never connects anywhere, so
|
|
20
|
+
// there is no address to check.
|
|
21
|
+
transport: transport,
|
|
20
22
|
secrets: canarySecrets,
|
|
21
23
|
tokens,
|
|
22
24
|
capabilities: sheet.needs,
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halonicjs/testing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Halonic's test suites for code outside the engine. @halonicjs/testing/integration is the conformance suite every integration runs against recorded responses, with its attack cases.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"halonic",
|
|
7
|
+
"testing",
|
|
8
|
+
"conformance",
|
|
9
|
+
"integration",
|
|
10
|
+
"security-testing"
|
|
11
|
+
],
|
|
5
12
|
"license": "Apache-2.0",
|
|
6
13
|
"repository": {
|
|
7
14
|
"type": "git",
|
|
@@ -23,7 +30,7 @@
|
|
|
23
30
|
"NOTICE"
|
|
24
31
|
],
|
|
25
32
|
"dependencies": {
|
|
26
|
-
"@halonicjs/adapters": "0.1.
|
|
33
|
+
"@halonicjs/adapters": "0.1.2",
|
|
27
34
|
"yaml": "2.9.1",
|
|
28
35
|
"zod": "4.6.7"
|
|
29
36
|
},
|