@halonicjs/testing 0.1.1 → 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/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 +2 -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/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- 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/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 +4 -2
- package/dist/core/events/src/index.js +2 -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 +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- 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 +3 -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 +3 -2
- package/dist/core/format/src/index.js +3 -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/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- 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/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- 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/chat.d.ts +8 -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 +13 -3
- 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 +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- 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 +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -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/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -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 +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- 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.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/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- 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 +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- 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/package.json +9 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** A run of a text in a word diff: its `text`, and whether the other text doesn't have it. */
|
|
2
|
+
export interface WordPiece {
|
|
3
|
+
readonly text: string;
|
|
4
|
+
readonly changed: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Both texts of a word diff, each cut into pieces that join back to the text. */
|
|
7
|
+
export interface WordDiff {
|
|
8
|
+
readonly before: readonly WordPiece[];
|
|
9
|
+
readonly after: readonly WordPiece[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The words that differ between two texts, so a page can mark them inside
|
|
13
|
+
* the text rather than show two whole texts to compare by eye.
|
|
14
|
+
*
|
|
15
|
+
* Words, spaces and punctuation are compared as tokens, keeping the longest
|
|
16
|
+
* run of common tokens (as `diffLines` does for lines). The spaces at either
|
|
17
|
+
* end of a changed run are left unmarked, so the marks sit on the words.
|
|
18
|
+
*
|
|
19
|
+
* @param before - the text as it was
|
|
20
|
+
* @param after - the text as it is now
|
|
21
|
+
* @returns the pieces of each text, joining back to `before` and `after`
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* diffWords("Write short sentences.", "Write short, warm sentences.").after;
|
|
25
|
+
* // [{ text: "Write short", changed: false }, { text: ", warm", changed: true },
|
|
26
|
+
* // { text: " sentences.", changed: false }]
|
|
27
|
+
*/
|
|
28
|
+
export declare function diffWords(before: string, after: string): WordDiff;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { diffLines } from "./line-diff.js";
|
|
2
|
+
/**
|
|
3
|
+
* Words, runs of spaces and single other characters (punctuation, symbols).
|
|
4
|
+
* Every character falls in one of them, so the tokens join back to the text.
|
|
5
|
+
*/
|
|
6
|
+
const tokenPattern = /[\p{L}\p{N}_]+|\s+|[^\p{L}\p{N}_\s]/gu;
|
|
7
|
+
/**
|
|
8
|
+
* The words that differ between two texts, so a page can mark them inside
|
|
9
|
+
* the text rather than show two whole texts to compare by eye.
|
|
10
|
+
*
|
|
11
|
+
* Words, spaces and punctuation are compared as tokens, keeping the longest
|
|
12
|
+
* run of common tokens (as `diffLines` does for lines). The spaces at either
|
|
13
|
+
* end of a changed run are left unmarked, so the marks sit on the words.
|
|
14
|
+
*
|
|
15
|
+
* @param before - the text as it was
|
|
16
|
+
* @param after - the text as it is now
|
|
17
|
+
* @returns the pieces of each text, joining back to `before` and `after`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* diffWords("Write short sentences.", "Write short, warm sentences.").after;
|
|
21
|
+
* // [{ text: "Write short", changed: false }, { text: ", warm", changed: true },
|
|
22
|
+
* // { text: " sentences.", changed: false }]
|
|
23
|
+
*/
|
|
24
|
+
export function diffWords(before, after) {
|
|
25
|
+
const beforeTokens = before.match(tokenPattern) ?? [];
|
|
26
|
+
const afterTokens = after.match(tokenPattern) ?? [];
|
|
27
|
+
// diffLines compares lines, so each distinct token becomes a line of its own number.
|
|
28
|
+
const numbers = new Map();
|
|
29
|
+
const asLines = (tokens) => tokens
|
|
30
|
+
.map((token) => {
|
|
31
|
+
const known = numbers.get(token);
|
|
32
|
+
if (known !== undefined)
|
|
33
|
+
return `${known}\n`;
|
|
34
|
+
numbers.set(token, numbers.size);
|
|
35
|
+
return `${numbers.size - 1}\n`;
|
|
36
|
+
})
|
|
37
|
+
.join("");
|
|
38
|
+
const changes = diffLines(asLines(beforeTokens), asLines(afterTokens));
|
|
39
|
+
const beforeChanged = new Array(beforeTokens.length).fill(false);
|
|
40
|
+
const afterChanged = new Array(afterTokens.length).fill(false);
|
|
41
|
+
for (const change of changes) {
|
|
42
|
+
markRun(beforeTokens, beforeChanged, change.beforeStart, change.beforeEnd);
|
|
43
|
+
markRun(afterTokens, afterChanged, change.afterStart, change.afterStart + change.added.length);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
before: piecesOf(beforeTokens, beforeChanged),
|
|
47
|
+
after: piecesOf(afterTokens, afterChanged),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Marks the tokens from `start` up to `end` as changed, but not the spaces at either end. */
|
|
51
|
+
function markRun(tokens, changed, start, end) {
|
|
52
|
+
let first = start;
|
|
53
|
+
let last = end;
|
|
54
|
+
while (first < last && isSpace(tokens[first]))
|
|
55
|
+
first++;
|
|
56
|
+
while (last > first && isSpace(tokens[last - 1]))
|
|
57
|
+
last--;
|
|
58
|
+
changed.fill(true, first, last);
|
|
59
|
+
}
|
|
60
|
+
function isSpace(token) {
|
|
61
|
+
return token !== undefined && /^\s+$/u.test(token);
|
|
62
|
+
}
|
|
63
|
+
/** The tokens joined into pieces, a new piece wherever `changed` flips. */
|
|
64
|
+
function piecesOf(tokens, changed) {
|
|
65
|
+
const pieces = [];
|
|
66
|
+
tokens.forEach((token, index) => {
|
|
67
|
+
const isChanged = changed[index] === true;
|
|
68
|
+
const last = pieces.at(-1);
|
|
69
|
+
if (last?.changed === isChanged) {
|
|
70
|
+
last.text += token;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
pieces.push({ text: token, changed: isChanged });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return pieces;
|
|
77
|
+
}
|
|
@@ -9,6 +9,9 @@ import type { YamlPath } from "./read.js";
|
|
|
9
9
|
* nothing is there.
|
|
10
10
|
* - `insert`: adds `value` to a list before the item at the index that ends
|
|
11
11
|
* `path`; the list's length adds it at the end.
|
|
12
|
+
* - `rename`: gives the map key that ends `path` the name `to`, in the same
|
|
13
|
+
* place in its map and with the same value. The key must be there and `to`
|
|
14
|
+
* must not be a key of that map yet; `to` equal to the old key changes nothing.
|
|
12
15
|
*
|
|
13
16
|
* A `set` that adds a new key to a map puts it at the end of that map, or
|
|
14
17
|
* right after the key `after` names; `after: null` puts it first. This is
|
|
@@ -29,6 +32,10 @@ export type YamlEdit = {
|
|
|
29
32
|
readonly kind: "insert";
|
|
30
33
|
readonly path: YamlPath;
|
|
31
34
|
readonly value: unknown;
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: "rename";
|
|
37
|
+
readonly path: YamlPath;
|
|
38
|
+
readonly to: string;
|
|
32
39
|
};
|
|
33
40
|
/**
|
|
34
41
|
* Applies an edit to plain data, the way `editYaml` must change what the
|
|
@@ -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()) {
|
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
|
},
|