@hanv89/arch-skill 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SYNTHETIC_MANIFEST = exports.SYNTHETIC_EXAMPLE = exports.SYNTHETIC_SKILL_MD = exports.SYNTHETIC_ICONS_VERSION = exports.SYNTHETIC_REQUIRES_ICONS = exports.SYNTHETIC_VERSION = void 0;
37
+ exports.installFetchMock = installFetchMock;
38
+ exports.failOnNthHeadFetchMock = failOnNthHeadFetchMock;
39
+ exports.mkTmpdir = mkTmpdir;
40
+ exports.rmTmpdir = rmTmpdir;
41
+ exports.silenceStderr = silenceStderr;
42
+ const fs = __importStar(require("node:fs"));
43
+ const path = __importStar(require("node:path"));
44
+ const os = __importStar(require("node:os"));
45
+ // Synthetic skill bundle used by every test suite that mocks the network.
46
+ // Keeping all three suites (adapters-roundtrip, all, version) on the same
47
+ // fixture eliminates per-file drift (e.g. SKILL.md version: 0.5.0 vs 0.6.0
48
+ // landed in earlier test files because the fixture was copy-pasted).
49
+ exports.SYNTHETIC_VERSION = "0.5.0";
50
+ exports.SYNTHETIC_REQUIRES_ICONS = ">=0.2.2";
51
+ exports.SYNTHETIC_ICONS_VERSION = "0.2.2";
52
+ exports.SYNTHETIC_SKILL_MD = [
53
+ "---",
54
+ "name: architecture-diagram",
55
+ "description: test fixture",
56
+ `version: ${exports.SYNTHETIC_VERSION}`,
57
+ `requires_icons: "${exports.SYNTHETIC_REQUIRES_ICONS}"`,
58
+ "---",
59
+ "# Test skill body",
60
+ "",
61
+ "This is a synthetic SKILL.md used only by the test fixtures.",
62
+ ].join("\n");
63
+ exports.SYNTHETIC_EXAMPLE = "@startuml\ntitle Test\n@enduml\n";
64
+ exports.SYNTHETIC_MANIFEST = {
65
+ $schema: "./manifest.schema.json",
66
+ name: "architecture-diagram",
67
+ version: exports.SYNTHETIC_VERSION,
68
+ requires_icons: exports.SYNTHETIC_REQUIRES_ICONS,
69
+ icons_version: exports.SYNTHETIC_ICONS_VERSION,
70
+ files: [
71
+ { src: "dist/skill/SKILL.md", dest: "SKILL.md", role: "skill" },
72
+ { src: "dist/skill/examples/01-context.puml", dest: "examples/01-context.puml", role: "example" },
73
+ ],
74
+ };
75
+ const realFetch = globalThis.fetch;
76
+ /**
77
+ * Returns 200 for the manifest, SKILL.md, and the one bundled example;
78
+ * 200 for any HEAD; 404 otherwise.
79
+ */
80
+ function installFetchMock() {
81
+ globalThis.fetch = (async (url, init) => {
82
+ const u = url.toString();
83
+ const method = (init?.method ?? "GET").toUpperCase();
84
+ if (method === "HEAD") {
85
+ return new Response(null, { status: 200 });
86
+ }
87
+ if (u.endsWith("/dist/skill/manifest.json")) {
88
+ return new Response(JSON.stringify(exports.SYNTHETIC_MANIFEST), { status: 200, headers: { "Content-Type": "application/json" } });
89
+ }
90
+ if (u.endsWith("/dist/skill/SKILL.md")) {
91
+ return new Response(exports.SYNTHETIC_SKILL_MD, { status: 200 });
92
+ }
93
+ if (u.endsWith("/dist/skill/examples/01-context.puml")) {
94
+ return new Response(exports.SYNTHETIC_EXAMPLE, { status: 200 });
95
+ }
96
+ return new Response("not found", { status: 404 });
97
+ });
98
+ return { restore: () => { globalThis.fetch = realFetch; } };
99
+ }
100
+ /**
101
+ * Like `installFetchMock` but the Nth HEAD request returns 404. Used by
102
+ * the rollback test to fail the third adapter's canary while the first
103
+ * two have already installed.
104
+ */
105
+ function failOnNthHeadFetchMock(failOnHeadIndex) {
106
+ let headCount = 0;
107
+ globalThis.fetch = (async (url, init) => {
108
+ const u = url.toString();
109
+ const method = (init?.method ?? "GET").toUpperCase();
110
+ if (method === "HEAD") {
111
+ headCount++;
112
+ if (headCount === failOnHeadIndex) {
113
+ return new Response(null, { status: 404 });
114
+ }
115
+ return new Response(null, { status: 200 });
116
+ }
117
+ if (u.endsWith("/dist/skill/manifest.json")) {
118
+ return new Response(JSON.stringify(exports.SYNTHETIC_MANIFEST), { status: 200, headers: { "Content-Type": "application/json" } });
119
+ }
120
+ if (u.endsWith("/dist/skill/SKILL.md")) {
121
+ return new Response(exports.SYNTHETIC_SKILL_MD, { status: 200 });
122
+ }
123
+ if (u.endsWith("/dist/skill/examples/01-context.puml")) {
124
+ return new Response(exports.SYNTHETIC_EXAMPLE, { status: 200 });
125
+ }
126
+ return new Response("not found", { status: 404 });
127
+ });
128
+ return {
129
+ restore: () => { globalThis.fetch = realFetch; },
130
+ headCount: () => headCount,
131
+ };
132
+ }
133
+ function mkTmpdir() {
134
+ return fs.mkdtempSync(path.join(os.tmpdir(), "arch-skill-test-"));
135
+ }
136
+ function rmTmpdir(dir) {
137
+ fs.rmSync(dir, { recursive: true, force: true });
138
+ }
139
+ // Silence stderr summary lines so the test reporter's output stays readable.
140
+ // IMPORTANT: do NOT silence stdout. Hijacking process.stdout.write inside a
141
+ // node:test test confuses the runner's buffered reporter — other tests' ✔
142
+ // lines get eaten by the capture buffer and silently drop from the count.
143
+ function silenceStderr() {
144
+ const orig = process.stderr.write.bind(process.stderr);
145
+ process.stderr.write = (_chunk) => true;
146
+ return { restore: () => { process.stderr.write = orig; } };
147
+ }