librebot-tools 0.0.0-stage → 0.4.4

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.
@@ -0,0 +1,109 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdtemp, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { parseBotFiles, validateFiles, exportBotFiles, scaffoldBotFiles, scaffoldBot, validateSource } from "../src/index.js";
7
+
8
+ const files = (extra = {}) => ({
9
+ "bot.yaml": "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n",
10
+ "instructions.md": "Be helpful.",
11
+ "README.md": "# T",
12
+ ...extra,
13
+ });
14
+
15
+ describe("root README documentation", () => {
16
+ it("parses trimmed UTF-8 documentation separately from prompt and knowledge", async () => {
17
+ const parsed = await parseBotFiles(files({
18
+ "README.md": new TextEncoder().encode(" \n# Welcome 界\n\nFor users.\n "),
19
+ "knowledge/README.md": "Knowledge index only.",
20
+ "knowledge/guide.md": "Reference material.",
21
+ }));
22
+ assert.equal(parsed.draft.readme, "# Welcome 界\n\nFor users.");
23
+ assert.equal(parsed.draft.botPrompt, "Be helpful.");
24
+ assert.deepEqual(parsed.draft.knowledge.map((entry) => entry.content), ["Reference material."]);
25
+ assert.deepEqual(parsed.source.knowledgeFiles, ["guide.md"]);
26
+ assert.deepEqual(parsed.assets, []);
27
+ });
28
+
29
+ it("rejects a missing root README even when the knowledge index exists", async () => {
30
+ const source = files({ "knowledge/README.md": "# Knowledge" });
31
+ delete source["README.md"];
32
+ const result = await validateFiles(source);
33
+ assert.equal(result.ok, false);
34
+ assert.deepEqual(result.errors, [{ file: "README.md", field: "", message: "is required" }]);
35
+ await assert.rejects(parseBotFiles(source), (error) => {
36
+ assert.deepEqual(error.errors, result.errors);
37
+ return true;
38
+ });
39
+ });
40
+
41
+ for (const readme of [undefined, null, 42, "", " \n\t "]) {
42
+ it(`rejects export with invalid readme ${JSON.stringify(readme)}`, async () => {
43
+ const { draft } = await parseBotFiles(files());
44
+ if (readme === undefined) delete draft.readme;
45
+ else draft.readme = readme;
46
+ assert.throws(() => exportBotFiles(draft), /requires a non-empty draft readme/);
47
+ });
48
+ }
49
+
50
+ it("trims exported documentation and rejects oversized documentation", async () => {
51
+ const { draft } = await parseBotFiles(files());
52
+ assert.equal(exportBotFiles({ ...draft, readme: " \n# Guide\n " })["README.md"], "# Guide");
53
+ assert.throws(
54
+ () => exportBotFiles({ ...draft, readme: "x".repeat(100001) }),
55
+ /readme is too long/,
56
+ );
57
+ });
58
+
59
+ it("round-trips root README without adding a bot.yaml field", async () => {
60
+ const parsed = await parseBotFiles(files({ "README.md": "# T\n\nUser guide." }));
61
+ const exported = exportBotFiles(parsed.draft);
62
+ assert.equal(exported["README.md"], parsed.draft.readme);
63
+ assert.doesNotMatch(exported["bot.yaml"], /readme/i);
64
+ const again = await parseBotFiles(exported);
65
+ assert.deepEqual(again.draft, parsed.draft);
66
+ });
67
+
68
+ for (const [name, value, message] of [
69
+ ["invalid UTF-8", new Uint8Array([0xc3, 0x28]), "must be UTF-8 text"],
70
+ ["empty text", "", "must not be empty"],
71
+ ["whitespace-only text", " \n\t\r ", "must not be empty"],
72
+ ["too-long text", "x".repeat(100001), "is too long (max 100000 chars)"],
73
+ ]) {
74
+ it(`rejects ${name} with a root README diagnostic`, async () => {
75
+ const source = files({ "README.md": value });
76
+ const result = await validateFiles(source);
77
+ assert.equal(result.ok, false);
78
+ assert.deepEqual(result.errors, [{ file: "README.md", field: "", message }]);
79
+ await assert.rejects(parseBotFiles(source), (error) => {
80
+ assert.deepEqual(error.errors, result.errors);
81
+ return true;
82
+ });
83
+ });
84
+ }
85
+
86
+ it("accepts the character limit after trimming, rather than a byte limit", async () => {
87
+ const readme = "界".repeat(100000);
88
+ const parsed = await parseBotFiles(files({ "README.md": ` \n${readme}\n ` }));
89
+ assert.equal(parsed.draft.readme, readme);
90
+ });
91
+
92
+ it("includes useful root documentation in file-map and on-disk scaffolds", async () => {
93
+ const source = scaffoldBotFiles({ name: "Helper" });
94
+ assert.match(source["README.md"], /^# Helper\n/);
95
+ assert.notEqual(source["README.md"], source["knowledge/README.md"]);
96
+ const parsed = await parseBotFiles(source);
97
+ assert.equal(parsed.draft.readme, source["README.md"].trim());
98
+ const dir = await mkdtemp(join(tmpdir(), "librebot-readme-"));
99
+ try {
100
+ const written = await scaffoldBot(dir, { name: "Helper" });
101
+ assert.ok(written.includes("README.md"));
102
+ const result = await validateSource(dir);
103
+ assert.equal(result.ok, true, JSON.stringify(result.errors));
104
+ assert.equal(result.draft.readme, parsed.draft.readme);
105
+ } finally {
106
+ await rm(dir, { recursive: true, force: true });
107
+ }
108
+ });
109
+ });
@@ -0,0 +1,186 @@
1
+ // Semantic cross-file rules: references must resolve, mounts must compose,
2
+ // declarations must stay within platform limits.
3
+
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { validateFiles } from "../src/index.js";
7
+
8
+ const base = (yaml) =>
9
+ validateFiles({
10
+ "bot.yaml":
11
+ "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n" +
12
+ yaml,
13
+ "instructions.md": "Be helpful.",
14
+ "README.md": "# T",
15
+ });
16
+
17
+ const messages = (result) => result.errors.map((e) => e.message);
18
+
19
+ describe("semantic cross-references", () => {
20
+ it("applies the draft quota to UTF-8 bytes rather than characters", async () => {
21
+ const files = {
22
+ "bot.yaml": "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n",
23
+ "instructions.md": "Be helpful.",
24
+ "README.md": "# T",
25
+ };
26
+ for (let i = 0; i < 4; i++) files[`knowledge/${i}.txt`] = "界".repeat(70_000);
27
+ const result = await validateFiles(files);
28
+ assert.equal(result.ok, false);
29
+ assert.ok(messages(result).some((message) => message.includes("750")));
30
+ });
31
+
32
+ it("rejects triggers whose deciderRole is not declared", async () => {
33
+ const result = await base(
34
+ "triggers:\n - key: triage\n label: T\n kind: gitrepo\n eventTypes: [issue.opened]\n deciderRole: slow\n deciderInstructions: decide\n",
35
+ );
36
+ assert.equal(result.ok, false);
37
+ assert.ok(messages(result).some((m) => m.includes("declared model roles")));
38
+ });
39
+
40
+ it("accepts API-only actions without a workspace mount", async () => {
41
+ const result = await base("actions: [{key: repo, kind: gitrepo, capabilities: [read_issue]}]\n");
42
+ assert.equal(result.ok, true);
43
+ assert.equal(result.draft.actions[0].key, "repo");
44
+ });
45
+
46
+ it("accepts every portable repository capability", async () => {
47
+ const capabilities = ["read_issue", "push_branch", "propose_change", "comment_issue", "search_issues", "read_change_request", "read_repository", "update_issue_labels", "react_issue", "update_issue_body", "update_issue_title", "publish_attachments", "merge_change_request"];
48
+ const result = await base(`workspace: [{key: source, path: ./code}]\nactions: [{key: repo, kind: gitrepo, capabilities: ${JSON.stringify(capabilities)}}]\n`);
49
+ assert.equal(result.ok, true);
50
+ assert.deepEqual(result.draft.actions[0].capabilities, capabilities);
51
+ });
52
+
53
+ it("parses and validates a bot authored with merge_change_request and change_request.checks_updated", async () => {
54
+ const result = await base("workspace: [{key: source, path: ./code}]\nactions: [{key: repo, kind: gitrepo, capabilities: [read_change_request, merge_change_request]}]\ntriggers: [{key: checks, label: Checks, kind: gitrepo, eventTypes: [change_request.checks_updated], deciderInstructions: Decide.}]\n");
55
+ assert.equal(result.ok, true);
56
+ assert.deepEqual(result.draft.actions[0].capabilities, ["read_change_request", "merge_change_request"]);
57
+ assert.deepEqual(result.draft.triggers[0].eventTypes, ["change_request.checks_updated"]);
58
+ assert.equal((await base("actions: [{key: repo, kind: gitrepo, capabilities: [merge_pull_request]}]\n")).ok, false);
59
+ });
60
+
61
+ it("rejects malformed action groups and native provider capabilities", async () => {
62
+ for (const value of [
63
+ "null", "read_issue", "[read_issue]",
64
+ "[{key: repo, kind: github, capabilities: [read_issue]}]",
65
+ "[{key: repo, kind: gitrepo, capabilities: [pull_request]}]",
66
+ "[{key: repo, kind: gitrepo, capabilities: [read_merge_request]}]",
67
+ "[{key: repo, kind: gitrepo, capabilities: []}]",
68
+ "[{key: repo, kind: gitrepo, capabilities: [read_issue, read_issue]}]",
69
+ JSON.stringify(Array.from({ length: 21 }, (_, i) => ({ key: `repo${i}`, kind: "gitrepo", capabilities: ["read_issue"] }))),
70
+ ]) {
71
+ assert.equal((await base(`actions: ${value}\n`)).ok, false, value);
72
+ }
73
+ });
74
+
75
+ it("keeps independent action keys even when labels match", async () => {
76
+ const result = await base("actions: [{key: primary, label: Repository, kind: gitrepo, capabilities: [read_issue]}, {key: secondary, label: Repository, kind: gitrepo, capabilities: [propose_change]}]\n");
77
+ assert.equal(result.ok, true);
78
+ assert.deepEqual(result.draft.actions.map((action) => action.key), ["primary", "secondary"]);
79
+ assert.equal((await base("actions: [{key: same, kind: gitrepo, capabilities: [read_issue]}, {key: same, kind: gitrepo, capabilities: [propose_change]}]\n")).ok, false);
80
+ });
81
+
82
+ it("rejects overlapping and duplicate mounts", async () => {
83
+ const overlap = await base("workspace:\n - {key: source, path: ./code}\n - {key: nested, path: ./code/deep}\n");
84
+ assert.equal(overlap.ok, false);
85
+ assert.ok(messages(overlap).some((m) => m.includes("overlap")));
86
+ const exclusive = await base(
87
+ "workspace:\n - {key: root, path: ./}\n - {key: source, path: ./code}\n",
88
+ );
89
+ assert.equal(exclusive.ok, false);
90
+ });
91
+
92
+ it("rejects platform-owned metadata in source", async () => {
93
+ for (const yaml of [
94
+ "visibility: private\n",
95
+ "workspace:\n - {id: legacy, key: source, path: ./code}\n",
96
+ "triggers:\n - {id: legacy, key: triage, label: T, kind: gitrepo, eventTypes: [issue.opened], deciderInstructions: decide}\n",
97
+ "connectors:\n - {id: legacy, label: C, tools: [search]}\n",
98
+ ]) {
99
+ const result = await base(yaml);
100
+ assert.equal(result.ok, false);
101
+ assert.ok(messages(result).some((message) => message.includes("unsupported field")));
102
+ }
103
+ });
104
+
105
+ it("preserves explicit keys across labels and paths and rejects duplicate keys", async () => {
106
+ const yaml = "workspace:\n - {key: source, label: Source, path: ./code}\ntriggers:\n - {key: triage, label: T, kind: gitrepo, eventTypes: [issue.opened], deciderInstructions: decide}\nconnectors:\n - {label: C, tools: [search]}\n";
107
+ const first = await base(yaml);
108
+ const second = await base(yaml.replace("label: Source", "label: Renamed").replace("./code", "./renamed").replace("label: T,", "label: Renamed,"));
109
+ assert.equal(first.ok, true);
110
+ assert.equal(second.ok, true);
111
+ assert.equal(second.draft.workspace[0].key, first.draft.workspace[0].key);
112
+ assert.equal(second.draft.triggers[0].key, first.draft.triggers[0].key);
113
+ assert.deepEqual(first.draft.connectors, second.draft.connectors);
114
+ const duplicate = await base("triggers:\n - {key: same, label: T, kind: gitrepo, eventTypes: [issue.opened], deciderInstructions: decide}\n - {key: same, label: Other, kind: gitrepo, eventTypes: [issue.closed], deciderInstructions: decide}\n");
115
+ assert.equal(duplicate.ok, false);
116
+ const sameLabel = await base("triggers:\n - {key: first, label: T, kind: gitrepo, eventTypes: [issue.opened], deciderInstructions: decide}\n - {key: second, label: T, kind: gitrepo, eventTypes: [issue.closed], deciderInstructions: decide}\n");
117
+ assert.equal(sameLabel.ok, true);
118
+ const duplicateConnectors = await base("connectors:\n - {label: C, tools: [search]}\n - {label: ' C ', tools: [other]}\n");
119
+ assert.equal(duplicateConnectors.ok, false);
120
+ });
121
+
122
+ it("rejects connector resources outside declared tools", async () => {
123
+ const result = await base(
124
+ "connectors:\n - label: C\n tools: [search]\n resources:\n - key: r\n label: R\n tools: [delete]\n",
125
+ );
126
+ assert.equal(result.ok, false);
127
+ assert.ok(messages(result).some((m) => m.includes("declared connector tool")));
128
+ });
129
+
130
+ it("rejects local-execution MCP declarations", async () => {
131
+ const result = await base(
132
+ "connectors:\n - label: C\n tools: [search]\n command: /bin/evil\n",
133
+ );
134
+ assert.equal(result.ok, false);
135
+ assert.ok(
136
+ messages(result).some(
137
+ (m) => m.includes("unsupported field") || m.includes("local-execution"),
138
+ ),
139
+ );
140
+ });
141
+
142
+ it("accepts a remote MCP endpoint and preserves model requirements", async () => {
143
+ const result = await validateFiles({
144
+ "bot.yaml":
145
+ "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n requirements: { vision: true, minContextWindow: 128000 }\nconnectors:\n - label: GitHub\n tools: [search]\n endpoint: https://mcp.example.com/rpc\n",
146
+ "instructions.md": "Be helpful.",
147
+ "README.md": "# T",
148
+ });
149
+ assert.equal(result.ok, true);
150
+ assert.equal(result.draft.connectors[0].endpoint, "https://mcp.example.com/rpc");
151
+ assert.equal(result.draft.modelRoles[0].requirements.vision, true);
152
+ assert.equal(result.draft.modelRoles[0].requirements.minContextWindow, 128000);
153
+ assert.equal(result.draft.modelRoles[0].requirements.tools, true);
154
+ });
155
+
156
+ it("parses structured knowledgeSources and rejects id collisions", async () => {
157
+ const good = await base(
158
+ "knowledgeSources:\n - id: docs\n name: Docs\n kind: resource\n url: https://example.com/docs\n - id: repo\n name: Repo\n kind: repo\n url: https://github.com/o/r\n ref: main\n",
159
+ );
160
+ assert.equal(good.ok, true);
161
+ assert.equal(good.draft.knowledge.length, 2);
162
+ assert.equal(good.draft.knowledge[1].ref, "main");
163
+
164
+ const collision = await validateFiles({
165
+ "bot.yaml":
166
+ "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\nknowledgeSources:\n - id: guide__intro.md\n name: Guide\n kind: resource\n url: https://example.com/g\n",
167
+ "instructions.md": "Be helpful.",
168
+ "README.md": "# T",
169
+ "knowledge/guide/intro.md": "hello",
170
+ });
171
+ assert.equal(collision.ok, false);
172
+ assert.ok(messages(collision).some((m) => m.includes("duplicate knowledge id")));
173
+ });
174
+
175
+ it("rejects empty SKILL.md like platform content validation", async () => {
176
+ const result = await validateFiles({
177
+ "bot.yaml":
178
+ "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n",
179
+ "instructions.md": "Be helpful.",
180
+ "README.md": "# T",
181
+ "skills/empty/SKILL.md": " \n",
182
+ });
183
+ assert.equal(result.ok, false);
184
+ assert.ok(messages(result).some((m) => m.includes("must not be empty")));
185
+ });
186
+ });
@@ -0,0 +1,41 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtemp, rm, appendFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import { parseSourcesYaml, sourcesHash, resolveSkillsLock, serializeLock, scaffoldBotFiles, writeFiles, parseBotSource } from '../src/index.js';
7
+ import { vendorContentHash } from '../src/skills-import.js';
8
+
9
+ describe('standard skills source locking', () => {
10
+ it('requires explicit installation consent for non-GitHub locators', async () => {
11
+ const sink = { errors: [], warnings: [] };
12
+ const sources = parseSourcesYaml({ version: 1, sources: ['https://gitlab.com/team/skills', './local-skills', 'owner/repo@review'] }, sink);
13
+ assert.deepEqual(sink.errors, []);
14
+ const result = await resolveSkillsLock({ sources });
15
+ assert.equal(result.errors.length, 3);
16
+ assert.ok(result.errors.every(error => error.message.includes('--network --vendor')));
17
+ });
18
+
19
+ it('loads content-locked vendor files from disk offline and rejects edited content', async (t) => {
20
+ const directory = await mkdtemp(join(tmpdir(), 'standard-skills-test-'));
21
+ t.after(() => rm(directory, { recursive: true, force: true }));
22
+ const doc = { version: 1, sources: [{ name: 'local', source: './local-skills' }] };
23
+ const sources = parseSourcesYaml(doc, { errors: [], warnings: [] });
24
+ const prefix = 'skills/.vendor/local/';
25
+ const vendorFiles = {
26
+ [prefix + 'review/SKILL.md']: new TextEncoder().encode('---\nname: review\ndescription: Review changes.\n---\nRead references/guide.md.\n'),
27
+ [prefix + 'review/references/guide.md']: new TextEncoder().encode('Check behavior, not implementation details.\n'),
28
+ };
29
+ const lock = { version: 1, sourcesHash: sourcesHash(sources.sources), resolved: [{ name: 'local', repo: 'skills-cli/./local-skills', contentSha256: vendorContentHash(vendorFiles, prefix), skills: [] }] };
30
+ const files = { ...scaffoldBotFiles({ name: 'Locked skills', description: 'Offline content lock' }), ...vendorFiles, 'skills/sources.yaml': JSON.stringify(doc), 'skills/sources.lock': serializeLock(lock) };
31
+ await writeFiles(directory, files);
32
+ const parsed = await parseBotSource(directory);
33
+ assert.ok(parsed.draft.skills.some(skill => skill.name === 'review'));
34
+ assert.ok(parsed.skillFiles.some(file => file.path === 'references/guide.md'));
35
+ const retained = await resolveSkillsLock({ sources, existingLock: lock, currentFiles: vendorFiles, vendor: true });
36
+ assert.deepEqual(retained.errors, []);
37
+ assert.equal(serializeLock(retained.lock), serializeLock(lock));
38
+ await appendFile(join(directory, prefix, 'review/references/guide.md'), 'Unreviewed changes.');
39
+ await assert.rejects(parseBotSource(directory), /locked digest/);
40
+ });
41
+ });
@@ -0,0 +1,135 @@
1
+ // Vendor extraction: crafted tarballs exercise long paths, GNU longnames,
2
+ // prefix splitting, and the size caps — all offline, no network.
3
+
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { gzipSync } from "node:zlib";
7
+ import { extractVendorFiles } from "../src/index.js";
8
+
9
+ function header(name, size, type = "0") {
10
+ const block = Buffer.alloc(512, 0);
11
+ const write = (value, offset, length) => {
12
+ Buffer.from(value).copy(block, offset, 0, length);
13
+ block[offset + Math.min(value.length, length)] = 0;
14
+ };
15
+ if (name.length <= 100) {
16
+ write(name, 0, 100);
17
+ } else {
18
+ // USTAR prefix split: tests the reader's prefix handling.
19
+ const slash = name.lastIndexOf("/", 155);
20
+ write(name.slice(0, slash), 345, 155);
21
+ write(name.slice(slash + 1), 0, 100);
22
+ }
23
+ block.write(size.toString(8).padStart(11, "0") + " ", 124);
24
+ block[156] = type.charCodeAt(0);
25
+ write("ustar", 257, 6);
26
+ let checksum = 256;
27
+ for (let i = 0; i < 512; i++) checksum += i >= 148 && i < 156 ? 32 : block[i];
28
+ block.write(checksum.toString(8).padStart(6, "0") + "\0 ", 148);
29
+ return block;
30
+ }
31
+
32
+ function gnuLongEntry(fullName) {
33
+ const nameBytes = Buffer.from(fullName + "\0");
34
+ const padded = Buffer.alloc(512 - (nameBytes.length % 512 || 512));
35
+ return Buffer.concat([header("././@LongLink", nameBytes.length, "L"), nameBytes, padded]);
36
+ }
37
+
38
+ function tarball(entries) {
39
+ const parts = [];
40
+ for (const { name, data, gnuLong } of entries) {
41
+ const bytes = Buffer.from(data);
42
+ if (gnuLong) parts.push(gnuLongEntry(name));
43
+ parts.push(header(gnuLong ? name.slice(-90) : name, bytes.length));
44
+ parts.push(bytes);
45
+ parts.push(Buffer.alloc(512 - (bytes.length % 512 || 512)));
46
+ }
47
+ parts.push(Buffer.alloc(1024));
48
+ return new Uint8Array(gzipSync(Buffer.concat(parts)));
49
+ }
50
+
51
+ describe("vendor extraction", () => {
52
+ it("extracts skill subtrees and skips unselected dirs", async () => {
53
+ const gz = tarball([
54
+ { name: "repo-abc/review/SKILL.md", data: "# Review\n" },
55
+ { name: "repo-abc/review/reference.md", data: "ref\n" },
56
+ { name: "repo-abc/other/SKILL.md", data: "# Other\n" },
57
+ ]);
58
+ const out = await extractVendorFiles({ name: "lib", skills: ["review"] }, gz);
59
+ assert.deepEqual(Object.keys(out).sort(), [
60
+ "skills/.vendor/lib/review/SKILL.md",
61
+ "skills/.vendor/lib/review/reference.md",
62
+ ]);
63
+ assert.equal(
64
+ new TextDecoder().decode(out["skills/.vendor/lib/review/SKILL.md"]),
65
+ "# Review\n",
66
+ );
67
+ });
68
+
69
+ it("discovers default selections and resolves long paths", async () => {
70
+ const longDir = "a".repeat(60) + "/" + "b".repeat(60);
71
+ const longSkill = "x".repeat(200);
72
+ const gz = tarball([
73
+ { name: "repo-abc/review/SKILL.md", data: "# R\n" },
74
+ { name: `repo-abc/${longDir}/SKILL.md`, data: "# Deep\n" },
75
+ { name: `repo-abc/${longDir}/notes.md`, data: "deep\n" },
76
+ { name: `repo-abc/${longSkill}/SKILL.md`, data: "# Gnu\n", gnuLong: true },
77
+ ]);
78
+ const out = await extractVendorFiles({ name: "lib", skills: [] }, gz);
79
+ assert.ok(out["skills/.vendor/lib/review/SKILL.md"]);
80
+ assert.ok(out[`skills/.vendor/lib/${longDir}/notes.md`]);
81
+ assert.ok(out[`skills/.vendor/lib/${longSkill}/SKILL.md`]);
82
+ });
83
+ it("vendors dedicated single-skill repos from the source root", async () => {
84
+ const gz = tarball([
85
+ { name: "repo-abc/SKILL.md", data: "# Solo\n" },
86
+ { name: "repo-abc/reference.md", data: "ref\n" },
87
+ ]);
88
+ const out = await extractVendorFiles({ name: "solo", skills: [] }, gz);
89
+ assert.deepEqual(Object.keys(out).sort(), [
90
+ "skills/.vendor/solo/SKILL.md",
91
+ "skills/.vendor/solo/reference.md",
92
+ ]);
93
+ const { parseBotFiles, parseSourcesYaml, resolveSkillsLock, serializeLock } = await import("../src/index.js");
94
+ const sha = "c".repeat(40);
95
+ const sources = parseSourcesYaml(
96
+ { version: 1, sources: [{ name: "solo", source: "octo/solo", ref: sha }] },
97
+ { errors: [], warnings: [] },
98
+ );
99
+ const { lock, errors } = await resolveSkillsLock({ sources });
100
+ assert.deepEqual(errors, []);
101
+ const reparsed = await parseBotFiles({
102
+ "bot.yaml":
103
+ "formatVersion: 1\nname: T\ndescription: D\nmodelRoles:\n - role: default\n label: Main\n",
104
+ "instructions.md": "Hi.",
105
+ "README.md": "# T",
106
+ "skills/sources.yaml": `version: 1\nsources:\n - name: solo\n source: octo/solo\n ref: ${sha}\n`,
107
+ "skills/sources.lock": serializeLock(lock),
108
+ ...out,
109
+ });
110
+ assert.equal(reparsed.draft.skills.length, 1);
111
+ assert.equal(reparsed.skillFiles.length, 1);
112
+ assert.equal(new TextDecoder().decode(reparsed.skillFiles[0].bytes), "ref\n");
113
+ });
114
+
115
+ it("rejects tarballs with traversal paths", async () => {
116
+ const { readTarEntries } = await import("../src/index.js");
117
+ const { gunzipSync } = await import("node:zlib");
118
+ const evil = tarball([{ name: "repo-abc/../../evil.md", data: "x\n" }]);
119
+ const raw = gunzipSync(Buffer.from(evil));
120
+ assert.throws(() => readTarEntries(new Uint8Array(raw)), /unsafe/);
121
+ });
122
+
123
+ it("fails loudly on oversized selected files instead of partial trees", async () => {
124
+ const big = Buffer.alloc(6 * 1024 * 1024, 1);
125
+ const gzBig = new Uint8Array(
126
+ gzipSync(
127
+ Buffer.concat([header("repo-abc/big/blob.bin", big.length), big, Buffer.alloc(1024)]),
128
+ ),
129
+ );
130
+ await assert.rejects(
131
+ extractVendorFiles({ name: "lib", skills: ["big"] }, gzBig),
132
+ /exceeds the size limit/,
133
+ );
134
+ });
135
+ });
@@ -0,0 +1,31 @@
1
+ import { it } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { validateFiles } from '../src/index.js';
4
+ const files = (kind, capabilities) => ({
5
+ 'bot.yaml': `formatVersion: 1\nname: Messenger\ndescription: Replies with permission\nmodelRoles:\n - {role: default, label: Main}\nactions:\n - {key: messaging, kind: ${kind}, capabilities: [${capabilities.join(', ')}]}\n`,
6
+ 'instructions.md': 'Use only owner-bound messaging authority.',
7
+ 'README.md': '# Messenger',
8
+ });
9
+ it('parses portable WhatsApp reads, text and reaction declarations', async () => {
10
+ const result = await validateFiles(files('whatsapp', ['read_messages', 'send_text', 'set_reaction', 'remove_reaction']));
11
+ assert.equal(result.ok, true, JSON.stringify(result.errors));
12
+ assert.deepEqual(result.draft.actions, [{ key: 'messaging', kind: 'whatsapp', capabilities: ['read_messages', 'send_text', 'set_reaction', 'remove_reaction'] }]);
13
+ });
14
+ it('rejects crossing repository and WhatsApp capabilities', async () => {
15
+ assert.equal((await validateFiles(files('gitrepo', ['send_text']))).ok, false);
16
+ assert.equal((await validateFiles(files('whatsapp', ['push_branch']))).ok, false);
17
+ assert.equal((await validateFiles(files('whatsapp', ['send_text', 'send_text']))).ok, false);
18
+ });
19
+ const triggered = (kind, events) => {
20
+ const source = files('whatsapp', ['read_messages']);
21
+ source['bot.yaml'] += `triggers:\n - key: incoming\n label: Incoming messaging\n kind: ${kind}\n eventTypes: [${events.join(', ')}]\n deciderInstructions: Decide whether to assist.\n`;
22
+ return source;
23
+ };
24
+ it('validates complete portable WhatsApp triggers and rejects event crossovers', async () => {
25
+ const result = await validateFiles(triggered('whatsapp', ['message.created', 'reaction.changed']));
26
+ assert.equal(result.ok, true, JSON.stringify(result.errors));
27
+ assert.equal(result.draft.triggers[0].kind, 'whatsapp');
28
+ assert.deepEqual(result.draft.triggers[0].eventTypes, ['message.created', 'reaction.changed']);
29
+ assert.equal((await validateFiles(triggered('gitrepo', ['message.created']))).ok, false);
30
+ assert.equal((await validateFiles(triggered('whatsapp', ['issue.opened']))).ok, false);
31
+ });