From 6c34b9a1272331527229954536f23af9fea179a2 Mon Sep 17 00:00:00 2001 From: konojunya Date: Sun, 6 Sep 2026 02:03:07 +0900 Subject: [PATCH] Generate shared agent guidance and skill from one source --- .github/workflows/ci.yaml | 37 ++++++++++++ AGENTS.md | 9 +++ README.md | 45 +++++++++++++- content/agent-workflow.md | 40 ++++++++++++ content/cli-release.json | 5 ++ content/skill-metadata.json | 5 ++ generated/guide/agent-workflow.md | 42 +++++++++++++ generated/manifest.json | 18 ++++++ generated/skills/stack-diagrams/SKILL.md | 48 +++++++++++++++ package.json | 13 ++++ scripts/generate.mjs | 77 ++++++++++++++++++++++++ scripts/generate.test.mjs | 64 ++++++++++++++++++++ scripts/smoke-skill.mjs | 34 +++++++++++ 13 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 AGENTS.md create mode 100644 content/agent-workflow.md create mode 100644 content/cli-release.json create mode 100644 content/skill-metadata.json create mode 100644 generated/guide/agent-workflow.md create mode 100644 generated/manifest.json create mode 100644 generated/skills/stack-diagrams/SKILL.md create mode 100644 package.json create mode 100644 scripts/generate.mjs create mode 100644 scripts/generate.test.mjs create mode 100644 scripts/smoke-skill.mjs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..a4fa6be --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,37 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + baseline: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 + with: + node-version: 22.14.0 + - name: Check whitespace + run: git diff --check "$(git hash-object -t tree /dev/null)" HEAD + - name: Check generator syntax + run: node --check scripts/generate.mjs + - name: Test shared-source generation and drift rejection + run: npm test + - name: Verify committed generated content + run: npm run check + - name: Verify and exercise published CLI + env: + GH_TOKEN: ${{ github.token }} + run: | + version=$(node -p 'JSON.parse(require("fs").readFileSync("content/cli-release.json")).version') + archive="stack-v${version}-x86_64-unknown-linux-gnu.tar.gz" + mkdir "$RUNNER_TEMP/stack-release" + gh release download "v${version}" --repo stack-sh/cli --pattern "$archive" --dir "$RUNNER_TEMP/stack-release" + gh attestation verify "$RUNNER_TEMP/stack-release/$archive" --repo stack-sh/cli + tar -xzf "$RUNNER_TEMP/stack-release/$archive" -C "$RUNNER_TEMP/stack-release" + STACK_CLI_BIN="$RUNNER_TEMP/stack-release/stack-v${version}-x86_64-unknown-linux-gnu/stack" npm run smoke diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e1d8b78 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,9 @@ +# Repository guide + +This repository owns shared user documentation and agent guidance. Write repository content, code comments, commits, and pull requests in English; translated documentation keeps its target language. + +Edit sources under `content/`, not files under `generated/`. Run `npm run generate`, `npm run check`, and `npm test`. Commit generated changes together with their sources. Keep generation deterministic and offline. + +Language syntax, schemas, and canonical examples belong to `stack-sh/specification`. CLI-specific contracts belong to `stack-sh/cli`. Link to those owners instead of creating competing contracts here. + +Preserve the public documentation URLs and the `npx skills add stack-sh/cli` installation entry point. Consumer updates must pin a merged provider commit and validate generated content before publication. Use topic branches and pull requests; never push implementation directly to main. diff --git a/README.md b/README.md index fb221f2..6e2c033 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# docs +# Stack documentation sources + Canonical user documentation and generated agent guidance for Stack architecture diagrams. + +## Ownership + +Edit the shared agent workflow in `content/agent-workflow.md`. Both the installable +skill and the human-readable workflow are generated from this one source. Skill +discovery metadata lives in `content/skill-metadata.json`, and published CLI +identity lives in `content/cli-release.json`. + +Language syntax, schemas, and canonical examples remain owned by +[stack-sh/specification](https://github.com/stack-sh/specification). +[stack-sh/cli](https://github.com/stack-sh/cli) owns native command behavior and the +`npx skills add stack-sh/cli` installation entry point. +[stack-sh/web](https://github.com/stack-sh/web) owns the playground and deployment +at [stack-diagram.com/docs](https://stack-diagram.com/docs). + +## Generate and verify + +Node.js 22 or newer is required. There are no generation dependencies or install scripts. + +```sh +npm run generate +npm test +npm run check +``` + +Commit source and generated changes together. Do not edit `generated/` directly. +Check mode rejects modified, missing, or unexpected generated files. Generation +does not silently delete old files. The manifest records SHA-256 values and the +published CLI revision; hashes prove byte integrity, not publisher identity. + +Consumers must pin a reviewed, merged commit and verify its manifest and files. +The CLI's source revision is distinct from the documentation revision: updating +instructions does not publish a new CLI binary. Recheck capability statements +against the released binary's help when updating the release lock; changing a +version string alone does not prove a feature is available. + +## Migration status + +Shared workflow generation is available here. CLI and Web consumption, the full +multilingual guide migration, and automated consumer freshness checks are still +being integrated. Existing public documentation and skill installation remain +available from their current repositories until those consumer changes land. diff --git a/content/agent-workflow.md b/content/agent-workflow.md new file mode 100644 index 0000000..af250bc --- /dev/null +++ b/content/agent-workflow.md @@ -0,0 +1,40 @@ +# Stack diagrams + +Deliver editable `.stack` source and, when rendering is available, an SVG. Preserve the requested architecture and existing unrelated content. Stack describes architecture; it does not provision resources or execute application code. + +## Start with the available tools + +Run `stack --version` and `stack help` before selecting commands. Use the installed binary's help, not unreleased repository instructions. The published CLI {{cliVersion}} supports `check`, `fmt`, and `render`; it does not support their `--json` flags. A newer version may support additional options: verify them using `stack help `. + +If the CLI is missing, consult the [installation guide](https://stack-diagram.com/docs/guide/getting-started.md) and [release distribution contract](https://github.com/stack-sh/cli/blob/v{{cliVersion}}/docs/distribution.md). Install only when the user's authorization allows it. Otherwise provide source with an explicit validation gap; do not report it as checked. No remote source upload is required. + +## Read only the relevant reference + +Start with [syntax](https://stack-diagram.com/docs/language/syntax.md), [nodes and groups](https://stack-diagram.com/docs/language/nodes-and-groups.md), and [edges and layout](https://stack-diagram.com/docs/language/edges-and-layout.md) when the grammar is unfamiliar. Find complete examples in the [gallery](https://stack-diagram.com/docs/examples/index.md). The [documentation index](https://stack-diagram.com/docs/llms.txt) links the remaining references. If the client cannot fetch one resource, try its Markdown page or report the missing information rather than inventing syntax. + +Non-obvious constraints: + +- One `stack 1.0` declaration and one named `diagram`; node/group IDs are globally unique. +- Declare edges at diagram scope. Endpoints are node IDs, not labels or groups. +- Model technologies using labels and `detail`; choose semantic `kind` values from the reference. Do not invent properties such as coordinates, colors, or ports. +- Prefer automatic layout or `direction` initially. `order` controls relative cross-axis ordering, not execution sequence; add `rank` or `order` only when the user needs that constraint. References must be direct children of that layout scope. +- Do not guess vendor icon IDs. Consult [provider icons](https://stack-diagram.com/docs/guide/provider-icons.md), query `stack icons list`, and verify the required pack is installed. Import downloads and terms acceptance need appropriate user authorization. If no pack is available, use the semantic kind fallback and explain that branded artwork is absent. + +## Generate, validate, and render + +For a new diagram, start with the smallest complete source that preserves the requested components and relationships. For an edit, inspect the existing source first and retain unrelated nodes, edges, labels, and comments. + +Using the user's actual filenames: + +```sh +stack check architecture.stack +stack fmt architecture.stack +stack check architecture.stack +stack render architecture.stack -o architecture.svg +``` + +`fmt` changes the source in place; avoid unrelated formatting when it would obscure a narrowly requested edit. Rendering to a file may replace it, so honor existing artifact ownership. + +Read both the exit status and diagnostics. An exit code of zero can still carry warnings. Fix unknown references or invalid syntax from the diagnostic ranges; never remove requested architecture merely to make validation pass. Investigate layout warnings without treating an optional visual hint as a required semantic relationship. Missing-icon warnings mean the image rendered with a fallback, not that provider artwork was found. Bound repeated repair attempts and report a remaining blocker rather than silently weakening the task. + +After rendering, inspect the SVG visually when a suitable viewer is available. Compiler success does not prove readable layout. Confirm the requested nodes, boundaries, relationships, and labels remain present. Report the source/SVG paths, CLI version, validation result, and any unresolved warnings or unverified visual behavior. diff --git a/content/cli-release.json b/content/cli-release.json new file mode 100644 index 0000000..9675f90 --- /dev/null +++ b/content/cli-release.json @@ -0,0 +1,5 @@ +{ + "repository": "stack-sh/cli", + "revision": "7f4066884f7902d4c582d45184f3a9019fe59bf7", + "version": "0.4.0" +} diff --git a/content/skill-metadata.json b/content/skill-metadata.json new file mode 100644 index 0000000..12b3eff --- /dev/null +++ b/content/skill-metadata.json @@ -0,0 +1,5 @@ +{ + "name": "stack-diagrams", + "description": "Create or edit Stack (.stack) software architecture diagrams, validate them with the Stack CLI, and render SVG. Use for Stack diagrams or when a user chooses Stack for architecture documentation; not for infrastructure provisioning or unrelated programming stacks.", + "license": "Apache-2.0" +} diff --git a/generated/guide/agent-workflow.md b/generated/guide/agent-workflow.md new file mode 100644 index 0000000..666fd28 --- /dev/null +++ b/generated/guide/agent-workflow.md @@ -0,0 +1,42 @@ + + +# Stack diagrams + +Deliver editable `.stack` source and, when rendering is available, an SVG. Preserve the requested architecture and existing unrelated content. Stack describes architecture; it does not provision resources or execute application code. + +## Start with the available tools + +Run `stack --version` and `stack help` before selecting commands. Use the installed binary's help, not unreleased repository instructions. The published CLI 0.4.0 supports `check`, `fmt`, and `render`; it does not support their `--json` flags. A newer version may support additional options: verify them using `stack help `. + +If the CLI is missing, consult the [installation guide](https://stack-diagram.com/docs/guide/getting-started.md) and [release distribution contract](https://github.com/stack-sh/cli/blob/v0.4.0/docs/distribution.md). Install only when the user's authorization allows it. Otherwise provide source with an explicit validation gap; do not report it as checked. No remote source upload is required. + +## Read only the relevant reference + +Start with [syntax](https://stack-diagram.com/docs/language/syntax.md), [nodes and groups](https://stack-diagram.com/docs/language/nodes-and-groups.md), and [edges and layout](https://stack-diagram.com/docs/language/edges-and-layout.md) when the grammar is unfamiliar. Find complete examples in the [gallery](https://stack-diagram.com/docs/examples/index.md). The [documentation index](https://stack-diagram.com/docs/llms.txt) links the remaining references. If the client cannot fetch one resource, try its Markdown page or report the missing information rather than inventing syntax. + +Non-obvious constraints: + +- One `stack 1.0` declaration and one named `diagram`; node/group IDs are globally unique. +- Declare edges at diagram scope. Endpoints are node IDs, not labels or groups. +- Model technologies using labels and `detail`; choose semantic `kind` values from the reference. Do not invent properties such as coordinates, colors, or ports. +- Prefer automatic layout or `direction` initially. `order` controls relative cross-axis ordering, not execution sequence; add `rank` or `order` only when the user needs that constraint. References must be direct children of that layout scope. +- Do not guess vendor icon IDs. Consult [provider icons](https://stack-diagram.com/docs/guide/provider-icons.md), query `stack icons list`, and verify the required pack is installed. Import downloads and terms acceptance need appropriate user authorization. If no pack is available, use the semantic kind fallback and explain that branded artwork is absent. + +## Generate, validate, and render + +For a new diagram, start with the smallest complete source that preserves the requested components and relationships. For an edit, inspect the existing source first and retain unrelated nodes, edges, labels, and comments. + +Using the user's actual filenames: + +```sh +stack check architecture.stack +stack fmt architecture.stack +stack check architecture.stack +stack render architecture.stack -o architecture.svg +``` + +`fmt` changes the source in place; avoid unrelated formatting when it would obscure a narrowly requested edit. Rendering to a file may replace it, so honor existing artifact ownership. + +Read both the exit status and diagnostics. An exit code of zero can still carry warnings. Fix unknown references or invalid syntax from the diagnostic ranges; never remove requested architecture merely to make validation pass. Investigate layout warnings without treating an optional visual hint as a required semantic relationship. Missing-icon warnings mean the image rendered with a fallback, not that provider artwork was found. Bound repeated repair attempts and report a remaining blocker rather than silently weakening the task. + +After rendering, inspect the SVG visually when a suitable viewer is available. Compiler success does not prove readable layout. Confirm the requested nodes, boundaries, relationships, and labels remain present. Report the source/SVG paths, CLI version, validation result, and any unresolved warnings or unverified visual behavior. diff --git a/generated/manifest.json b/generated/manifest.json new file mode 100644 index 0000000..4d5798d --- /dev/null +++ b/generated/manifest.json @@ -0,0 +1,18 @@ +{ + "schemaVersion": "1.0", + "cli": { + "repository": "stack-sh/cli", + "revision": "7f4066884f7902d4c582d45184f3a9019fe59bf7", + "version": "0.4.0" + }, + "files": [ + { + "path": "skills/stack-diagrams/SKILL.md", + "sha256": "a7f39a9d3da0f7074ea348bebb0260a642f202ee5f2026742c08972f75c7f2a6" + }, + { + "path": "guide/agent-workflow.md", + "sha256": "66fe4c3c97afad3a740d9ab824c5aae3f43783bfa251fe0347666b38bc3afc9b" + } + ] +} diff --git a/generated/skills/stack-diagrams/SKILL.md b/generated/skills/stack-diagrams/SKILL.md new file mode 100644 index 0000000..e48f3ed --- /dev/null +++ b/generated/skills/stack-diagrams/SKILL.md @@ -0,0 +1,48 @@ +--- +name: "stack-diagrams" +description: "Create or edit Stack (.stack) software architecture diagrams, validate them with the Stack CLI, and render SVG. Use for Stack diagrams or when a user chooses Stack for architecture documentation; not for infrastructure provisioning or unrelated programming stacks." +license: "Apache-2.0" +--- + + + +# Stack diagrams + +Deliver editable `.stack` source and, when rendering is available, an SVG. Preserve the requested architecture and existing unrelated content. Stack describes architecture; it does not provision resources or execute application code. + +## Start with the available tools + +Run `stack --version` and `stack help` before selecting commands. Use the installed binary's help, not unreleased repository instructions. The published CLI 0.4.0 supports `check`, `fmt`, and `render`; it does not support their `--json` flags. A newer version may support additional options: verify them using `stack help `. + +If the CLI is missing, consult the [installation guide](https://stack-diagram.com/docs/guide/getting-started.md) and [release distribution contract](https://github.com/stack-sh/cli/blob/v0.4.0/docs/distribution.md). Install only when the user's authorization allows it. Otherwise provide source with an explicit validation gap; do not report it as checked. No remote source upload is required. + +## Read only the relevant reference + +Start with [syntax](https://stack-diagram.com/docs/language/syntax.md), [nodes and groups](https://stack-diagram.com/docs/language/nodes-and-groups.md), and [edges and layout](https://stack-diagram.com/docs/language/edges-and-layout.md) when the grammar is unfamiliar. Find complete examples in the [gallery](https://stack-diagram.com/docs/examples/index.md). The [documentation index](https://stack-diagram.com/docs/llms.txt) links the remaining references. If the client cannot fetch one resource, try its Markdown page or report the missing information rather than inventing syntax. + +Non-obvious constraints: + +- One `stack 1.0` declaration and one named `diagram`; node/group IDs are globally unique. +- Declare edges at diagram scope. Endpoints are node IDs, not labels or groups. +- Model technologies using labels and `detail`; choose semantic `kind` values from the reference. Do not invent properties such as coordinates, colors, or ports. +- Prefer automatic layout or `direction` initially. `order` controls relative cross-axis ordering, not execution sequence; add `rank` or `order` only when the user needs that constraint. References must be direct children of that layout scope. +- Do not guess vendor icon IDs. Consult [provider icons](https://stack-diagram.com/docs/guide/provider-icons.md), query `stack icons list`, and verify the required pack is installed. Import downloads and terms acceptance need appropriate user authorization. If no pack is available, use the semantic kind fallback and explain that branded artwork is absent. + +## Generate, validate, and render + +For a new diagram, start with the smallest complete source that preserves the requested components and relationships. For an edit, inspect the existing source first and retain unrelated nodes, edges, labels, and comments. + +Using the user's actual filenames: + +```sh +stack check architecture.stack +stack fmt architecture.stack +stack check architecture.stack +stack render architecture.stack -o architecture.svg +``` + +`fmt` changes the source in place; avoid unrelated formatting when it would obscure a narrowly requested edit. Rendering to a file may replace it, so honor existing artifact ownership. + +Read both the exit status and diagnostics. An exit code of zero can still carry warnings. Fix unknown references or invalid syntax from the diagnostic ranges; never remove requested architecture merely to make validation pass. Investigate layout warnings without treating an optional visual hint as a required semantic relationship. Missing-icon warnings mean the image rendered with a fallback, not that provider artwork was found. Bound repeated repair attempts and report a remaining blocker rather than silently weakening the task. + +After rendering, inspect the SVG visually when a suitable viewer is available. Compiler success does not prove readable layout. Confirm the requested nodes, boundaries, relationships, and labels remain present. Report the source/SVG paths, CLI version, validation result, and any unresolved warnings or unverified visual behavior. diff --git a/package.json b/package.json new file mode 100644 index 0000000..735a3f8 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "@stack-sh/docs", + "version": "0.1.0", + "private": true, + "type": "module", + "license": "Apache-2.0", + "scripts": { + "generate": "node scripts/generate.mjs", + "check": "node scripts/generate.mjs --check", + "test": "node --test scripts/*.test.mjs", + "smoke": "node scripts/smoke-skill.mjs" + } +} diff --git a/scripts/generate.mjs b/scripts/generate.mjs new file mode 100644 index 0000000..d6247fb --- /dev/null +++ b/scripts/generate.mjs @@ -0,0 +1,77 @@ +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = fileURLToPath(new URL('../', import.meta.url)); + +export function renderGuidance(workflow, metadata, release) { + assert.match(release.version, /^\d+\.\d+\.\d+$/); + assert.match(release.revision, /^[a-f0-9]{40}$/); + assert.equal(release.repository, 'stack-sh/cli'); + assert.match(metadata.name, /^[a-z][a-z0-9-]{0,63}$/); + assert.equal(metadata.license, 'Apache-2.0'); + assert.equal(typeof metadata.description, 'string'); + assert.ok(metadata.description.length > 0); + // JSON-quoted strings are valid YAML scalar values, including colons and newlines. + const frontmatter = ['---', ...Object.entries(metadata).map(([key, value]) => `${key}: ${JSON.stringify(value)}`), '---', ''].join('\n'); + const rendered = workflow.replaceAll('{{cliVersion}}', release.version).trimEnd() + '\n'; + assert.ok(!/\{\{[^}]+\}\}/.test(rendered), 'Unknown template token'); + const notice = '\n\n'; + return { + 'skills/stack-diagrams/SKILL.md': frontmatter + '\n' + notice + rendered, + 'guide/agent-workflow.md': notice + rendered, + }; +} + +async function filePaths(directory, prefix = '') { + const entries = await readdir(directory, { withFileTypes: true }).catch(error => { + if (error.code === 'ENOENT') return []; + throw error; + }); + const paths = []; + for (const entry of entries) { + const relative = path.posix.join(prefix, entry.name); + assert.ok(!entry.isSymbolicLink(), `Symlink not allowed in generated content: ${relative}`); + if (entry.isDirectory()) paths.push(...await filePaths(path.join(directory, entry.name), relative)); + else paths.push(relative); + } + return paths.sort(); +} + +export async function generate(directory = root, check = false) { + const workflow = await readFile(path.join(directory, 'content/agent-workflow.md'), 'utf8'); + const metadata = JSON.parse(await readFile(path.join(directory, 'content/skill-metadata.json'), 'utf8')); + const release = JSON.parse(await readFile(path.join(directory, 'content/cli-release.json'), 'utf8')); + const outputs = renderGuidance(workflow, metadata, release); + const manifest = { + schemaVersion: '1.0', + cli: release, + files: Object.entries(outputs).map(([file, content]) => ({ + path: file, + sha256: createHash('sha256').update(content).digest('hex'), + })), + }; + outputs['manifest.json'] = JSON.stringify(manifest, null, 2) + '\n'; + const outputDirectory = path.join(directory, 'generated'); + const expected = Object.keys(outputs).sort(); + const existing = await filePaths(outputDirectory); + const obsolete = existing.filter(file => !expected.includes(file)); + assert.deepEqual(obsolete, [], 'Remove obsolete generated files explicitly before generating'); + if (check) assert.deepEqual(existing, expected, 'Generated file inventory drift'); + for (const [file, content] of Object.entries(outputs)) { + const target = path.join(outputDirectory, file); + if (check) assert.equal(await readFile(target, 'utf8'), content, `Generated content drift: ${file}`); + else { + await mkdir(path.dirname(target), { recursive: true }); + await writeFile(target, content); + } + } + return outputs; +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + assert.ok(process.argv.slice(2).every(arg => arg === '--check'), 'Only --check is supported'); + await generate(root, process.argv.includes('--check')); +} diff --git a/scripts/generate.test.mjs b/scripts/generate.test.mjs new file mode 100644 index 0000000..06f46a7 --- /dev/null +++ b/scripts/generate.test.mjs @@ -0,0 +1,64 @@ +import assert from 'node:assert/strict'; +import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; +import os from 'node:os'; +import path from 'node:path'; +import test from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { generate, renderGuidance } from './generate.mjs'; + +const root = fileURLToPath(new URL('../', import.meta.url)); +async function fixture(t) { + const directory = await mkdtemp(path.join(os.tmpdir(), 'stack-docs-generation-')); + t.after(() => rm(directory, { recursive: true, force: true })); + await cp(path.join(root, 'content'), path.join(directory, 'content'), { recursive: true }); + return directory; +} + +test('one shared instruction change updates skill and guide with deterministic output', async t => { + const directory = await fixture(t); + const before = await generate(directory); + const sourcePath = path.join(directory, 'content/agent-workflow.md'); + const source = await readFile(sourcePath, 'utf8'); + await writeFile(sourcePath, source + '\nKeep the existing diagram title.\n'); + const after = await generate(directory); + for (const file of ['skills/stack-diagrams/SKILL.md', 'guide/agent-workflow.md']) { + assert.notEqual(before[file], after[file]); + assert.ok(after[file].includes('Keep the existing diagram title.')); + } + assert.deepEqual(await generate(directory), after); + await generate(directory, true); +}); + +test('release lock updates all rendered version references', async t => { + const directory = await fixture(t); + const releasePath = path.join(directory, 'content/cli-release.json'); + const release = JSON.parse(await readFile(releasePath, 'utf8')); + release.version = '9.8.7'; + await writeFile(releasePath, JSON.stringify(release)); + const outputs = await generate(directory); + for (const file of ['skills/stack-diagrams/SKILL.md', 'guide/agent-workflow.md']) { + assert.ok(outputs[file].includes('9.8.7')); + assert.ok(!outputs[file].includes('0.4.0')); + } +}); + +test('check rejects modified, missing, and unexpected generated files', async t => { + const directory = await fixture(t); + await generate(directory); + const target = path.join(directory, 'generated/guide/agent-workflow.md'); + await writeFile(target, 'manual edit'); + await assert.rejects(generate(directory, true), /Generated content drift/); + await generate(directory); + await rm(target); + await assert.rejects(generate(directory, true), /inventory drift/); + await generate(directory); + await writeFile(path.join(directory, 'generated/unexpected.md'), 'old output'); + await assert.rejects(generate(directory, true), /obsolete generated files/); +}); + +test('unknown tokens and mutable provider revisions fail closed', () => { + const metadata = { name: 'stack-diagrams', description: 'Create Stack diagrams.', license: 'Apache-2.0' }; + const release = { repository: 'stack-sh/cli', revision: 'a'.repeat(40), version: '0.4.0' }; + assert.throws(() => renderGuidance('{{missing}}', metadata, release), /Unknown template token/); + assert.throws(() => renderGuidance('content', metadata, { ...release, revision: 'main' })); +}); diff --git a/scripts/smoke-skill.mjs b/scripts/smoke-skill.mjs new file mode 100644 index 0000000..bf4c525 --- /dev/null +++ b/scripts/smoke-skill.mjs @@ -0,0 +1,34 @@ +import assert from 'node:assert/strict'; +import { execFile } from 'node:child_process'; +import { mkdtemp, readFile, rm } from 'node:fs/promises'; +import os from 'node:os'; +import path from 'node:path'; +import { promisify } from 'node:util'; + +const execute = promisify(execFile); +const binary = process.env.STACK_CLI_BIN; +assert.ok(binary && path.isAbsolute(binary), 'STACK_CLI_BIN must be an absolute binary path'); +const release = JSON.parse(await readFile(new URL('../content/cli-release.json', import.meta.url), 'utf8')); +const skill = await readFile(new URL('../generated/skills/stack-diagrams/SKILL.md', import.meta.url), 'utf8'); +const temporary = await mkdtemp(path.join(os.tmpdir(), 'stack-docs-skill-smoke-')); +try { + const run = args => execute(binary, args, { cwd: temporary, env: { ...process.env, XDG_CONFIG_HOME: path.join(temporary, 'config') }, timeout: 30_000 }); + assert.equal((await run(['--version'])).stdout, `stack ${release.version}\n`); + await run(['init', '-o', 'architecture.stack']); + const commands = [...skill.matchAll(/```sh\n([\s\S]*?)```/g)].flatMap(match => match[1].trim().split('\n')); + assert.ok(commands.length >= 4); + for (const command of commands) { + const [program, ...args] = command.trim().split(/\s+/); + assert.equal(program, 'stack'); + assert.ok(['check', 'fmt', 'render'].includes(args[0]), 'Only local validation commands are allowed in the smoke workflow'); + const result = await run(args); + assert.equal(result.stderr, '', `Unexpected diagnostic from ${command}`); + } + const svg = await readFile(path.join(temporary, 'architecture.svg'), 'utf8'); + assert.match(svg, //); + await run(['fmt', '--check', 'architecture.stack']); + console.log(`Executed ${commands.length} generated skill commands against published CLI ${release.version}.`); +} finally { + await rm(temporary, { recursive: true, force: true }); +}