diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 58be40bb0..2aa23b71c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -709,6 +709,22 @@ and reference builds too. Cleanup shares the assembly lock and refuses to run during an assembly. It preserves source, dependencies and `output/` review evidence. Custom output and cache locations need their own cleanup. +### Lua declaration source links + +The Lua reference links a declaration to its line in Git when the exported +file’s SHA-256 matches the file at that revision. Older exports still +supply descriptions, signatures and examples. + +To rebuild the links for `v0.1.1`, check out the tag in +`../libtmux-lua-v0.1.1`. From a Lua tooling checkout with declaration +hashes and support for the release’s example launcher, run the native exporter. + +```console +$ luajit scripts/docs/docs.lua export \ + --source ../libtmux-lua-v0.1.1 \ + --output ../libtmux-lua-v0.1.1/docs/_build +``` + ## Auditing page heads `site/scripts/audit-head.mjs` reads the head of every page and reports what diff --git a/packages/api-model/src/doc/roles.ts b/packages/api-model/src/doc/roles.ts index 9211c2601..5dc3636b4 100644 --- a/packages/api-model/src/doc/roles.ts +++ b/packages/api-model/src/doc/roles.ts @@ -298,6 +298,7 @@ const SYNTAX: Record> = { // Swift doc comment ``Server`` is a symbol link, not code. swift: new Set(['docc']), ruby: new Set(['yard']), + lua: new Set(['markdown-link']), cxx: new Set([]), kotlin: new Set(['kdoc', 'jsdoc']), scala: new Set(['scaladoc', 'jsdoc']), diff --git a/packages/api-model/src/languages/lua-examples.ts b/packages/api-model/src/languages/lua-examples.ts index 8abbde228..d2c362614 100644 --- a/packages/api-model/src/languages/lua-examples.ts +++ b/packages/api-model/src/languages/lua-examples.ts @@ -4,7 +4,13 @@ export interface LuaExampleManifest { schema: number /** `launcher` is a shell script that starts the tmux daemon; programs that start their own omit it. */ setup: { lua: string; luv: string; launcher?: string } - examples: { id: string; symbols: string[]; file: string; description: string; stdout: string }[] + examples: { id: string; symbols: string[]; file: string; description: string; stdout: string; min_tmux?: string }[] +} + +export interface LuaExampleOptions { + releaseRock?: string + localCheckout?: boolean + matchesExample?: (path: string, content: string) => boolean } /** Preserve complete source files exported by Lua's native documentation tool. */ @@ -12,7 +18,7 @@ export function attachCompleteLuaExamples( symbols: ApiSymbol[], manifest: LuaExampleManifest | undefined, files: { path: string; content: string }[] | undefined, - source: { repository: string; revision: string }, + source: { repository: string; revision: string } & LuaExampleOptions, ): void { if (manifest === undefined) return const require = (condition: unknown, message: string): void => { @@ -32,10 +38,33 @@ export function attachCompleteLuaExamples( const code = matches[0].content require(typeof code === 'string' && code.trim() && code.endsWith('\n') && !code.includes('\r'), `source file must retain complete LF bytes: ${path}`) + require(!source.matchesExample || source.matchesExample(path, code), + `${path} differs from the selected checkout; regenerate the native Lua docs artifact with scripts/docs/docs.lua export`) return code } const launcher = launcherPath === undefined ? undefined : { path: launcherPath, code: read(launcherPath) } + const rock = source.releaseRock + require(rock === undefined || /^[0-9][0-9a-z.-]*-[1-9]\d*$/.test(rock), 'invalid numbered rock argument') const url = (path: string) => `https://github.com/${source.repository}/blob/${source.revision}/${path}` + const installLuv = `$ luarocks --tree ./rocks install luv ${manifest.setup.luv} &&\n` + let install: string + let setup: string + if (source.localCheckout) { + install = installLuv + ' luarocks --tree ./rocks make rockspecs/libtmux-scm-1.rockspec\n' + setup = 'From the root of the local Lua checkout that produced this preview, build the SCM rock.' + } else if (rock) { + install = installLuv + ` luarocks --tree ./rocks install libtmux ${rock} &&\n` + + ' eval "$(luarocks --tree ./rocks path)"\n' + setup = 'Install the numbered rock in a new directory.' + } else { + install = installLuv + ' rocks="$PWD/rocks" &&\n' + + ' (cd ../libtmux-lua && luarocks --tree "$rocks" make rockspecs/libtmux-scm-1.rockspec)\n' + const sourceTree = `https://github.com/${source.repository}/tree/${source.revision}` + setup = `Put an empty example directory next to a copy of the [Lua source revision](${sourceTree}) named \`libtmux-lua\`. Build the SCM rock from the example directory.` + } + const launcherGuide = source.localCheckout ? '`examples/api/README.md` for launcher prerequisites' + : `the [launcher prerequisites](${url('examples/api/README.md')})` + const launcherSetup = launcher ? [`See ${launcherGuide}.`] : [] const seen = new Set() const ids = new Set() for (const example of manifest.examples) { @@ -45,42 +74,53 @@ export function attachCompleteLuaExamples( require(typeof example.description === 'string' && example.description.trim(), 'task description is missing') require(typeof example.stdout === 'string' && example.stdout.trim() && example.stdout.endsWith('\n'), 'expected output is missing') + require(example.min_tmux === undefined || (typeof example.min_tmux === 'string' && /^\d+\.\d+$/.test(example.min_tmux)), + 'invalid tmux floor') require(Array.isArray(example.symbols) && example.symbols.length, 'API targets are missing') const code = read(example.file) - const name = `${example.id}.lua` + const name = source.localCheckout ? example.file : `${example.id}.lua` + const shell = source.localCheckout ? launcherPath : 'run.sh' const blocks: NonNullable = [ { lang: 'console', - intro: `${example.description} Use Lua 5.1 or newer with LuaRocks, tmux 3.3a or newer, and a C compiler and CMake for luv on Linux. In a new directory, install the library and its standalone runtime dependency from LuaRocks:`, - code: '$ luarocks --tree ./rocks install luv &&\n' + - ' luarocks --tree ./rocks install libtmux &&\n' + - ' eval "$(luarocks --tree ./rocks path)"\n', + intro: [ + example.description, + `Use Lua 5.1 to 5.5 or LuaJIT with LuaRocks, tmux ${example.min_tmux ?? '3.3a'} or newer, and a C compiler and CMake for luv on Linux.`, + ...launcherSetup, + setup, + ].join(' '), + code: install, }, ...(launcher === undefined ? [] : [{ lang: 'sh', - intro: 'Save this complete launcher as `run.sh`. It starts a private tmux daemon and cleans up after success or failure. A failed daemon shutdown reports and retains its socket directory.', - sourceUrl: url(launcher.path), + intro: source.localCheckout ? `Use \`${launcher.path}\` from the same checkout.` + : 'Save the complete launcher as `run.sh`. It starts and stops a private tmux daemon. A failed shutdown reports and retains its socket directory.', + sourceUrl: source.localCheckout ? undefined : url(launcher.path), code: launcher.code, }]), { lang: 'lua', - intro: launcher === undefined - ? `Save the complete program as \`${name}\`. It starts its own private tmux server, uses it and stops it, so no existing session is needed.` - : `Save the complete program as \`${name}\`. Closing the library connection leaves the daemon running; the launcher owns its lifetime.`, - sourceUrl: url(example.file), + intro: source.localCheckout ? `Use \`${name}\` from the same checkout.` + : launcher === undefined + ? `Save the complete program as \`${name}\`. It starts its own private tmux server and stops it before exiting, including after a failure.` + : `Save the complete program as \`${name}\` beside \`run.sh\`. Closing the connection leaves the daemon running. The launcher owns its lifetime.`, + sourceUrl: source.localCheckout ? undefined : url(example.file), code, }, launcher === undefined ? { lang: 'console', - intro: 'Run the saved program. It runs `/usr/bin/tmux`; set `TMUX_BIN` to another absolute path to use a different binary. Assertions and operation errors produce a failing exit status:', + intro: (source.localCheckout ? 'Run the program from that checkout.' : 'Run the saved program.') + + ' Set `TMUX_BIN` to use an absolute path other than `/usr/bin/tmux`.', code: `$ eval "$(luarocks --tree ./rocks path)" &&\n lua ${name}\n`, } : { lang: 'console', - intro: 'Run the saved files. Assertions and operation errors produce a failing exit status:', - code: `$ eval "$(luarocks --tree ./rocks path)" &&\n sh run.sh ${name}\n`, + intro: (source.localCheckout ? 'Run the files from that checkout.' : 'Run the saved files together.') + + ' The launcher uses tmux on `PATH` unless `TMUX_BIN` selects another binary.', + code: `$ eval "$(luarocks --tree ./rocks path)" &&\n sh ${shell} "${name}"\n`, }, + { lang: 'text', intro: 'Expected output.', code: example.stdout }, ] for (const id of example.symbols) { require(!seen.has(id), `duplicate API target: ${id}`) diff --git a/packages/api-model/src/languages/lua.ts b/packages/api-model/src/languages/lua.ts index 2625bf4a7..83a43684d 100644 --- a/packages/api-model/src/languages/lua.ts +++ b/packages/api-model/src/languages/lua.ts @@ -1,5 +1,6 @@ import type { ApiModel, ApiSymbol, DocBlock, Param, Signature } from '../model.ts' -import { attachCompleteLuaExamples, type LuaExampleManifest } from './lua-examples.ts' +import { isCanonicalPath } from '../products.ts' +import { attachCompleteLuaExamples, type LuaExampleManifest, type LuaExampleOptions } from './lua-examples.ts' interface LuaNode { name?: string @@ -29,7 +30,7 @@ interface LuaDeclaration extends LuaNode { interface LuaArtifact { schema: number port: string - source: { repository: string; revision: string } + source: { repository: string; revision: string; files?: { path: string; sha256: string }[] } exporter: { name: string; version: number; luals: string } package: { name: string; version: string; source_tag: string } declarations: LuaDeclaration[] @@ -37,9 +38,20 @@ interface LuaArtifact { api_examples?: LuaExampleManifest } +interface LuaDeclarationSource { + revision: string + /** SHA-256 of the file at the citation revision. */ + sha256: (path: string) => string | undefined +} + +interface LuaExtractionOptions extends LuaExampleOptions { + declarationSource?: LuaDeclarationSource +} + function assertArtifact(input: unknown, expectedRevision?: string): LuaArtifact { const artifact = input as LuaArtifact - if (artifact?.schema !== 1 || artifact.port !== 'lua' || !Array.isArray(artifact.declarations)) { + if (artifact?.schema !== 1 || artifact.port !== 'lua' || !Array.isArray(artifact.declarations) || + artifact.source?.repository !== 'libtmux/libtmux-lua') { throw new Error('Lua documentation artifact has an unsupported schema') } if (expectedRevision && artifact.source?.revision !== expectedRevision) { @@ -57,14 +69,33 @@ function doc(text?: string): DocBlock | undefined { return { summary, body: body.join('\n\n') || undefined } } -function source(node: LuaNode, artifact: LuaArtifact) { - return { - file: node.file ?? '', - line: node.start?.[0], +function declarationSourceReader(artifact: LuaArtifact, citation: LuaDeclarationSource | undefined) { + const hashes = new Map() + const files = artifact.source.files + if (files !== undefined && !Array.isArray(files)) { + throw new Error('Lua declaration source files must be an array') + } + for (const entry of files ?? []) { + if (!isCanonicalPath(entry?.path) || !entry.path.startsWith('lua/') || !entry.path.endsWith('.lua') || + typeof entry.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(entry.sha256) || hashes.has(entry.path)) { + throw new Error('Lua declaration source files contain an invalid or repeated entry') + } + hashes.set(entry.path, { sha256: entry.sha256 }) + } + + const provenance = { repo: artifact.source.repository, - revision: artifact.source.revision, + revision: citation?.revision ?? artifact.source.revision, extractedRevision: artifact.source.revision, } + return ({ file, start }: LuaNode): ApiSymbol['source'] => { + const entry = file && hashes.get(file) + if (file && entry && citation) { + entry.verified ??= citation.sha256(file) === entry.sha256 + if (entry.verified) return { ...provenance, file, line: start?.[0] } + } + return { ...provenance, file: '' } + } } const argName = (argument?: LuaArg) => @@ -145,8 +176,13 @@ function originOf( return undefined } -export function extractLua(input: unknown, expectedRevision?: string): ApiModel { +export function extractLua( + input: unknown, + expectedRevision?: string, + options: LuaExtractionOptions = {}, +): ApiModel { const artifact = assertArtifact(input, expectedRevision) + const declarationSource = declarationSourceReader(artifact, options.declarationSource) const symbols: ApiSymbol[] = [] const byName = new Map(artifact.declarations.map((d) => [d.name, d])) for (const declaration of artifact.declarations) { @@ -165,7 +201,7 @@ export function extractLua(input: unknown, expectedRevision?: string): ApiModel // The declaration's own text, not `defines`: an alias's define holds the // generated listing of its values. doc: doc(declaration.rawdesc ?? declaration.desc), - source: source(ownerSource, artifact), + source: declarationSource(ownerSource), }) for (const field of declaration.fields) { if (!field.name) continue @@ -193,12 +229,15 @@ export function extractLua(input: unknown, expectedRevision?: string): ApiModel product: 'core', apiScope: 'exported', type: callable ? undefined : field.view, - source: source(field, artifact), + source: declarationSource(field), ...(inheritedFrom ? { inheritedFrom } : {}), }) } } - attachCompleteLuaExamples(symbols, artifact.api_examples, artifact.examples, artifact.source) + attachCompleteLuaExamples(symbols, artifact.api_examples, artifact.examples, { + ...artifact.source, + ...options, + }) return { port: 'lua', repo: artifact.source.repository, @@ -207,9 +246,9 @@ export function extractLua(input: unknown, expectedRevision?: string): ApiModel sources: [{ product: 'core', package: artifact.package.name, - version: artifact.package.version, + version: options.releaseRock ?? artifact.package.version, repo: artifact.source.repository, - revision: artifact.source.revision, + revision: options.declarationSource?.revision ?? artifact.source.revision, extractedRevision: artifact.source.revision, }], symbols, diff --git a/packages/api-model/src/products.ts b/packages/api-model/src/products.ts index bda698ef4..efd525199 100644 --- a/packages/api-model/src/products.ts +++ b/packages/api-model/src/products.ts @@ -23,6 +23,11 @@ export function inheritProductFromOwners(symbols: ApiSymbol[]): void { } } +/** A relative path inside a repository: no escape, no query, no hidden separator. */ +export const isCanonicalPath = (file: unknown): file is string => typeof file === 'string' && file !== '' && !file.startsWith('/') + && !/[\\?#%\0\n\r]/.test(file) && !/^[a-z]:/i.test(file) + && file.split('/').every((part) => part !== '' && part !== '.' && part !== '..') + /** * Build a source link from the declaration's repository before the port fallback. * A file the model embeds links to its source page, `/sources//`. diff --git a/packages/api-model/test/lua-examples.test.ts b/packages/api-model/test/lua-examples.test.ts index fff0974a3..cf908117a 100644 --- a/packages/api-model/test/lua-examples.test.ts +++ b/packages/api-model/test/lua-examples.test.ts @@ -3,19 +3,25 @@ import type { ApiSymbol } from '../src/model.ts' import { attachCompleteLuaExamples, type LuaExampleManifest } from '../src/languages/lua-examples.ts' const source = { repository: 'libtmux/libtmux-lua', revision: 'a'.repeat(40) } +const taggedSource = { ...source, releaseRock: '0.1.1-1' } const program = 'local text = ""\nprint(text)\n' const launcher = '#!/bin/sh\nset -eu\nlua "$1"\n' +const launcherPath = 'examples/api/run.sh' const files = [ { path: 'examples/api/connect.lua', content: program }, - { path: 'examples/api/run.sh', content: launcher }, { path: 'examples/ordinary.lua', content: 'print("not a complete example")\n' }, ] +const releaseFiles = [...files, { path: launcherPath, content: launcher }] const manifest = (): LuaExampleManifest => ({ schema: 1, - setup: { lua: '5.5.1', luv: '1.52.1-0', launcher: 'examples/api/run.sh' }, + setup: { lua: '5.5.1', luv: '1.52.1-0' }, examples: [{ id: 'connect', symbols: ['libtmux.Runtime:connect'], file: 'examples/api/connect.lua', description: 'Connect to a tmux daemon.', stdout: 'connected\n' }], }) +const releaseManifest = (path = launcherPath) => { + const value = manifest() + return { ...value, setup: { ...value.setup, launcher: path } } +} const target = (): ApiSymbol => ({ id: 'libtmux.Runtime:connect', name: 'connect', kind: 'method', modifiers: [], signatures: [], source: { file: 'lua/libtmux/_internal/runtime.lua', revision: source.revision }, @@ -23,41 +29,120 @@ const target = (): ApiSymbol => ({ }) describe('complete Lua API examples from native artifacts', () => { - it('retains native docs, exact full files, registry setup, and both source links', () => { + it('keeps the source build and direct command for programs that own their server', () => { const symbol = target() attachCompleteLuaExamples([symbol], manifest(), files, source) expect(symbol.doc?.summary).toBe('Existing native documentation.') const examples = symbol.doc!.examples! - expect(examples).toHaveLength(4) + expect(examples.map((example) => example.lang)).toEqual(['console', 'lua', 'console', 'text']) + expect(examples[1].code).toBe(program) + expect(examples[1].sourceUrl).toBe(`https://github.com/${source.repository}/blob/${source.revision}/examples/api/connect.lua`) + expect(examples[0].code).toBe('$ luarocks --tree ./rocks install luv 1.52.1-0 &&\n' + + ' rocks="$PWD/rocks" &&\n' + + ' (cd ../libtmux-lua && luarocks --tree "$rocks" make rockspecs/libtmux-scm-1.rockspec)\n') + expect(examples[0].intro).toContain(`https://github.com/${source.repository}/tree/${source.revision}`) + expect(examples[0].intro).toContain('Lua 5.1 to 5.5 or LuaJIT') + expect(examples[0].intro).toContain('tmux 3.3a or newer') + expect(examples[0].intro).not.toContain('launcher prerequisites') + expect(examples[1].intro).toContain('`connect.lua`') + expect(examples[1].intro).toContain('starts its own private tmux server') + expect(examples[1].intro).not.toMatch(/launcher/i) + expect(examples[2].intro).toContain('Run the saved program.') + expect(examples[2].intro).toContain('`TMUX_BIN`') + expect(examples[2].code).toBe('$ eval "$(luarocks --tree ./rocks path)" &&\n lua connect.lua\n') + expect(examples.some((example) => example.lang === 'sh' || example.code.includes('run.sh'))).toBe(false) + expect(examples.some((example) => example.code.includes('not a complete example'))).toBe(false) + }) + + it('retains the legacy launcher bytes, numbered rock and quoted run command', () => { + const symbol = target() + attachCompleteLuaExamples([symbol], releaseManifest(), releaseFiles, taggedSource) + const examples = symbol.doc!.examples! + expect(examples.map((example) => example.lang)).toEqual(['console', 'sh', 'lua', 'console', 'text']) + expect(examples[0].code).toBe('$ luarocks --tree ./rocks install luv 1.52.1-0 &&\n' + + ' luarocks --tree ./rocks install libtmux 0.1.1-1 &&\n' + + ' eval "$(luarocks --tree ./rocks path)"\n') + expect(examples[0].intro).toContain(`https://github.com/${source.repository}/blob/${source.revision}/examples/api/README.md`) expect(examples[1].code).toBe(launcher) + expect(examples[1].sourceUrl).toBe(`https://github.com/${source.repository}/blob/${source.revision}/${launcherPath}`) expect(examples[2].code).toBe(program) - expect(examples[1].sourceUrl).toBe(`https://github.com/${source.repository}/blob/${source.revision}/examples/api/run.sh`) - expect(examples[2].sourceUrl).toBe(`https://github.com/${source.repository}/blob/${source.revision}/examples/api/connect.lua`) - expect(examples[0].code).toBe('$ luarocks --tree ./rocks install luv &&\n' + - ' luarocks --tree ./rocks install libtmux &&\n' + - ' eval "$(luarocks --tree ./rocks path)"\n') - expect(examples[0].intro).toContain('Lua 5.1 or newer') - expect(examples[0].intro).not.toMatch(/git|clone/i) - expect(examples[2].intro).toContain('`connect.lua`') - expect(examples[3].code).toBe('$ eval "$(luarocks --tree ./rocks path)" &&\n sh run.sh connect.lua\n') - expect(examples.some((example) => example.code.includes('not a complete example'))).toBe(false) + expect(examples[2].intro).toContain('The launcher owns its lifetime') + expect(examples[3].intro).toContain('The launcher uses tmux on `PATH` unless `TMUX_BIN` selects another binary.') + expect(examples[3].code).toBe('$ eval "$(luarocks --tree ./rocks path)" &&\n sh run.sh "connect.lua"\n') }) - it('shows plain run commands for a manifest without a launcher', () => { - const value = manifest() - delete value.setup.launcher + it('installs the numbered rock for a tag with a standalone example', () => { const symbol = target() - attachCompleteLuaExamples([symbol], value, files.filter((file) => file.path !== 'examples/api/run.sh'), source) + attachCompleteLuaExamples([symbol], manifest(), files, taggedSource) const examples = symbol.doc!.examples! - expect(examples.map((example) => example.lang)).toEqual(['console', 'lua', 'console']) - expect(examples[0].code).toContain('luarocks --tree ./rocks install libtmux') - expect(examples[1].code).toBe(program) - expect(examples[1].sourceUrl).toBe(`https://github.com/${source.repository}/blob/${source.revision}/examples/api/connect.lua`) - expect(examples[1].intro).toContain('`connect.lua`') - expect(examples[1].intro).toContain('its own private tmux server') - expect(examples[2].code).toBe('$ eval "$(luarocks --tree ./rocks path)" &&\n lua connect.lua\n') - expect(examples[2].intro).toContain('TMUX_BIN') - expect(JSON.stringify(examples)).not.toMatch(/launcher|run\.sh/) + expect(examples[0].code).toContain('luarocks --tree ./rocks install libtmux 0.1.1-1') + expect(examples[2].code).toContain('lua connect.lua') + }) + + it('builds the captured source for a checkout with a launcher', () => { + const symbol = target() + attachCompleteLuaExamples([symbol], releaseManifest(), releaseFiles, source) + const examples = symbol.doc!.examples! + expect(examples[0].code).toContain('make rockspecs/libtmux-scm-1.rockspec') + expect(examples[3].code).toContain('sh run.sh "connect.lua"') + }) + + it('uses the checkout that supplied a local example', () => { + const symbol = target() + attachCompleteLuaExamples([symbol], manifest(), files, { ...source, localCheckout: true }) + const examples = symbol.doc!.examples! + expect(examples[0].intro).toContain('the local Lua checkout that produced this preview') + expect(examples[0].intro).not.toContain('https://github.com/') + expect(examples[0].code).toBe('$ luarocks --tree ./rocks install luv 1.52.1-0 &&\n' + + ' luarocks --tree ./rocks make rockspecs/libtmux-scm-1.rockspec\n') + expect(examples[1]).toMatchObject({ lang: 'lua', code: program }) + expect(examples[1].intro).toContain('`examples/api/connect.lua`') + expect(examples[1].sourceUrl).toBeUndefined() + expect(examples[2].intro).toContain('Run the program from that checkout.') + expect(examples[2].code).toBe('$ eval "$(luarocks --tree ./rocks path)" &&\n lua examples/api/connect.lua\n') + }) + + it('uses local launcher files when a checkout at a tag has working changes', () => { + const symbol = target() + attachCompleteLuaExamples([symbol], releaseManifest(), releaseFiles, { ...taggedSource, localCheckout: true }) + const examples = symbol.doc!.examples! + expect(examples[0].intro).toContain('`examples/api/README.md`') + expect(examples[0].intro).not.toContain('https://github.com/') + expect(examples[0].code).not.toContain('install libtmux 0.1.1-1') + expect(examples[1].sourceUrl).toBeUndefined() + expect(examples[2].sourceUrl).toBeUndefined() + expect(examples[3].code).toContain('sh examples/api/run.sh "examples/api/connect.lua"') + }) + + it.each([ + ['the clean source lacks the program', manifest(), files, false, 'examples/api/connect.lua', undefined], + ['the working program has changed', manifest(), files, true, 'examples/api/connect.lua', program + '-- edited\n'], + ['the launcher has changed', releaseManifest(), releaseFiles, true, launcherPath, launcher + '# edited\n'], + ] as const)('refuses a stale export when %s', (_label, selected, bundled, localCheckout, path, actual) => { + const checkout = new Map(bundled.map((row) => [row.path, row.content])) + if (actual === undefined) checkout.delete(path) + else checkout.set(path, actual) + expect(() => attachCompleteLuaExamples([target()], selected, bundled, { + ...source, + localCheckout, + matchesExample: (file: string, content: string) => checkout.get(file) === content, + })).toThrow(`${path} differs from the selected checkout; regenerate the native Lua docs artifact`) + }) + + it('accepts a numbered prerelease rock', () => { + const symbol = target() + attachCompleteLuaExamples([symbol], releaseManifest(), releaseFiles, { ...source, releaseRock: '0.1.0alpha4-1' }) + expect(symbol.doc?.examples?.[0].code).toContain('luarocks --tree ./rocks install libtmux 0.1.0alpha4-1') + }) + + it('renders the example-specific tmux floor and recorded output', () => { + const symbol = target() + const base = manifest() + const value = { ...base, examples: [{ ...base.examples[0], min_tmux: '3.7' }] } + attachCompleteLuaExamples([symbol], value, files, source) + const examples = symbol.doc!.examples! + expect(examples[0].intro).toContain('tmux 3.7 or newer') + expect(examples.at(-1)).toEqual({ lang: 'text', intro: 'Expected output.', code: 'connected\n' }) }) it('preserves historical native artifacts without the opt-in manifest', () => { @@ -68,7 +153,7 @@ describe('complete Lua API examples from native artifacts', () => { }) it('rejects missing or ambiguous full-file payloads and changed line endings', () => { - for (const invalid of [files.slice(0, 1), [...files, files[0]], + for (const invalid of [files.slice(1), [...files, files[0]], files.map((file) => ({ ...file, content: file.content.replaceAll('\n', '\r\n') }))]) { expect(() => attachCompleteLuaExamples([target()], manifest(), invalid, source)).toThrow() } @@ -83,10 +168,10 @@ describe('complete Lua API examples from native artifacts', () => { it('rejects unsafe paths and absent runtime or output contracts', () => { for (const mutate of [ - (value: LuaExampleManifest) => { value.setup.launcher = '../run.sh' }, (value: LuaExampleManifest) => { value.examples[0].file = '../../connect.lua' }, (value: LuaExampleManifest) => { value.setup.lua = 'latest' }, (value: LuaExampleManifest) => { value.setup.luv = 'latest' }, + (value: LuaExampleManifest) => { value.examples[0].min_tmux = 'current' }, (value: LuaExampleManifest) => { value.examples[0].stdout = '' }, (value: LuaExampleManifest) => { value.examples[0].description = '' }, ]) { @@ -100,11 +185,19 @@ describe('complete Lua API examples from native artifacts', () => { .toThrow(/Lua repository/) }) - it('still checks a launcher the manifest names', () => { - const value = manifest() - expect(() => attachCompleteLuaExamples([target()], value, files.filter((file) => file.path !== 'examples/api/run.sh'), source)) - .toThrow(/resolve once: examples\/api\/run\.sh/) - value.setup.launcher = 'examples/api/other.sh' - expect(() => attachCompleteLuaExamples([target()], value, files, source)).toThrow(/unexpected launcher path/) + it('requires exactly one complete file at the supported launcher path', () => { + for (const payload of [files, [...releaseFiles, { path: launcherPath, content: launcher }]]) { + expect(() => attachCompleteLuaExamples([target()], releaseManifest(), payload, source)) + .toThrow(/resolve once: examples\/api\/run\.sh/) + } + const badLineEndings = [...files, { path: launcherPath, content: launcher.replaceAll('\n', '\r\n') }] + expect(() => attachCompleteLuaExamples([target()], releaseManifest(), badLineEndings, source)) + .toThrow(/complete LF bytes: examples\/api\/run\.sh/) + for (const path of ['../run.sh', 'examples/api/other.sh', '']) { + expect(() => attachCompleteLuaExamples([target()], releaseManifest(path), releaseFiles, source)) + .toThrow(/unexpected launcher path/) + } + expect(() => attachCompleteLuaExamples([target()], releaseManifest(), releaseFiles, { ...source, releaseRock: 'scm-1' })) + .toThrow(/numbered rock argument/) }) }) diff --git a/packages/api-model/test/native-adapters.test.ts b/packages/api-model/test/native-adapters.test.ts index 3fcbbe989..e6c6196fb 100644 --- a/packages/api-model/test/native-adapters.test.ts +++ b/packages/api-model/test/native-adapters.test.ts @@ -1,3 +1,4 @@ +import { sourceUrl } from '../src/products.ts' import { describe, expect, it } from 'vitest' import { extractLua } from '../src/languages/lua.ts' import { extractRuby } from '../src/languages/ruby.ts' @@ -208,7 +209,11 @@ describe('Lua native documentation adapter', () => { } it('keeps module functions and renders receiver methods with colon identity', () => { - const model = extractLua(artifact, REVISION) + const file = 'lua/libtmux/_internal/runtime.lua' + const sha256 = 'c'.repeat(64) + const model = extractLua({ ...artifact, source: { ...artifact.source, files: [{ path: file, sha256 }] } }, REVISION, { + declarationSource: { revision: REVISION, sha256: () => sha256 }, + }) expect(model.port).toBe('lua') expect(model.sources?.[0]).toMatchObject({ package: 'libtmux', version: '0.1.0alpha1-1' }) expect(model.symbols.map((symbol) => symbol.id)).toEqual([ @@ -373,3 +378,61 @@ describe('Lua native documentation adapter', () => { }) }) }) + +describe('Lua declaration source identity', () => { + const source = { repository: 'libtmux/libtmux-lua', revision: REVISION } + const pinned = 'lua/libtmux/_internal/buffer.lua' + const changed = 'lua/libtmux/_internal/server.lua' + const added = 'lua/libtmux/_internal/program.lua' + const pinnedHash = 'b'.repeat(64) + const changedHash = 'c'.repeat(64) + const artifact = { + schema: 1, + port: 'lua', + source: { ...source, files: [{ path: pinned, sha256: pinnedHash }, { path: changed, sha256: changedHash }] }, + exporter: { name: 'scripts/docs/docs.lua', version: 1, luals: '3.19.1' }, + package: { name: 'libtmux', version: '0.1.1-1', source_tag: 'v0.1.1' }, + declarations: [ + { name: 'libtmux.Ticket', defines: [{ file: pinned, start: [12, 0] }], fields: [ + { name: 'read', file: changed, start: [30, 0], view: 'string', rawdesc: 'Current declaration.' }, + { name: 'wait', file: added, start: [50, 0], view: 'fun()', rawdesc: 'New declaration.' }, + ] }, + ], + } + + const revision = 'e'.repeat(40) + const declarationSource = { revision, sha256: (path: string) => path === pinned ? pinnedHash : 'd'.repeat(64) } + + it('links only declarations whose export matches the cited file', () => { + const model = extractLua(artifact, source.revision, { declarationSource }) + const [type, read, wait] = model.symbols + expect(sourceUrl(model, type)).toBe(`https://github.com/${source.repository}/blob/${revision}/${pinned}#L12`) + expect(type.source.extractedRevision).toBe(source.revision) + expect(sourceUrl(model, read)).toBeUndefined() + expect(read.source).toEqual({ file: '', repo: source.repository, revision, extractedRevision: source.revision }) + expect(sourceUrl(model, wait)).toBeUndefined() + expect(read.doc?.summary).toBe('Current declaration.') + expect(wait.doc?.summary).toBe('New declaration.') + }) + + it('omits declaration links from legacy exports, even with a cited revision', () => { + const model = extractLua({ ...artifact, source }, source.revision, { declarationSource }) + expect(model.symbols.map((symbol) => sourceUrl(model, symbol))).toEqual([undefined, undefined, undefined]) + }) + + it('omits links until the caller verifies the cited files', () => { + const model = extractLua(artifact, source.revision) + expect(model.symbols.map((symbol) => sourceUrl(model, symbol))).toEqual([undefined, undefined, undefined]) + }) + + it.each([ + ['null inventory', null], + ['null entry', [null]], + ['invalid digest', [{ path: pinned, sha256: 'short' }]], + ['path outside Lua', [{ path: 'lua/../README.md', sha256: pinnedHash }]], + ['duplicate path', [artifact.source.files[0], artifact.source.files[0]]], + ])('rejects source file proof with %s', (_reason, files) => { + expect(() => extractLua({ ...artifact, source: { ...source, files } }, source.revision, { declarationSource })) + .toThrow(/Lua declaration source files/) + }) +}) diff --git a/scripts/gen-api-model.mjs b/scripts/gen-api-model.mjs index 42b329c01..818d56b18 100644 --- a/scripts/gen-api-model.mjs +++ b/scripts/gen-api-model.mjs @@ -12,7 +12,9 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, import { homedir, tmpdir } from 'node:os' import { dirname, isAbsolute, join, relative, resolve } from 'node:path' import { fileURLToPath } from 'node:url' +import { isDeepStrictEqual } from 'node:util' import { PORTS as PORT_DEFS } from '../site/src/lib/ports.ts' +import { buildTarget, releaseRockForBuild } from '../site/src/lib/versions.ts' import { extractDoxygen } from '../packages/api-model/src/languages/doxygen.ts' import { extractLua } from '../packages/api-model/src/languages/lua.ts' import { extractPerlArtifact } from '../packages/api-model/src/languages/perl.ts' @@ -38,7 +40,7 @@ import { attachCompleteJvmExamples } from '../packages/api-model/src/languages/j import { attachCompleteSwiftExamples } from '../packages/api-model/src/languages/swift-examples.ts' import { mapLine, parseHunks } from '../packages/api-model/src/source-lines.ts' import { cargoFeatureNames } from './lib/cargo-features.mjs' -import { resolveCheckout } from './lib/port-checkout.mjs' +import { committedBytes, resolveCheckout } from './lib/port-checkout.mjs' import { extractProject } from '../packages/api-model/src/project.ts' import { scopeProductSymbols } from '../packages/api-model/src/product-exports.ts' import { inheritProductFromOwners } from '../packages/api-model/src/products.ts' @@ -694,8 +696,54 @@ for (const [port, cfg] of Object.entries(PORTS)) { process.exit(1) } const artifact = JSON.parse(readFileSync(artifactPath, 'utf8')) - const nativeExtractors = { raku: extractRakuArtifact, perl: extractPerlArtifact, ruby: extractRuby, lua: extractLua, powershell: extractPowerShell, julia: extractJulia, elixir: extractElixir, ocaml: extractOcamlArtifact, haskell: extractHaskellArtifact, clojure: extractClojure, lisp: extractCommonLisp, erlang: extractErlang } - model = nativeExtractors[port](artifact, head) + const nativeExtractors = { raku: extractRakuArtifact, perl: extractPerlArtifact, ruby: extractRuby, powershell: extractPowerShell, julia: extractJulia, elixir: extractElixir, ocaml: extractOcamlArtifact, haskell: extractHaskellArtifact, clojure: extractClojure, lisp: extractCommonLisp, erlang: extractErlang } + if (port === 'lua') { + const status = git(checkout, 'status', '--porcelain', '--untracked-files=normal') + if (status === undefined) throw new Error(`gen-api-model: cannot inspect the Lua checkout at ${checkout}`) + const localCheckout = status !== '' || revision !== head + const build = artifact.api_examples !== undefined && process.env.LIBTMUX_DOCS_PORT === port + ? buildTarget(process.env) : undefined + const releaseManifest = build && (build.kind === 'tag' || build.kind === 'alias') + ? git(checkout, 'show', `${head}:release.json`) + : undefined + // The public tag carries the package version even in older exporter artifacts. + const declaredRock = releaseManifest === undefined ? artifact.package?.version : JSON.parse(releaseManifest).version + const releaseRock = build && releaseRockForBuild(build, declaredRock) + if (releaseRock) { + const ref = `refs/tags/${releaseRock.tag}` + const commit = git(checkout, 'rev-parse', '--verify', `${ref}^{commit}`) + if (commit !== head) { + throw new Error(`gen-api-model: Lua checkout ${head} does not match ${ref} (${commit ?? 'missing tag'})`) + } + } + const readSource = (path, commit = localCheckout ? undefined : head) => { + if (commit !== undefined) return committedBytes(checkout, commit, path) + try { return readFileSync(join(checkout, path)) } catch { return undefined } + } + if (artifact.api_examples !== undefined) { + const manifestPath = 'examples/api/manifest.json' + let manifest + try { + manifest = JSON.parse(readSource(manifestPath)?.toString('utf8') ?? '') + } catch { + manifest = undefined + } + if (!isDeepStrictEqual(artifact.api_examples, manifest)) { + throw new Error(`${manifestPath} differs from the selected checkout. Regenerate the native Lua docs artifact with scripts/docs/docs.lua export.`) + } + } + const matchesExample = (path, content) => readSource(path)?.equals(Buffer.from(content)) ?? false + const declarationSource = revision ? { + revision, + sha256(path) { + const bytes = readSource(path, revision) + return bytes && createHash('sha256').update(bytes).digest('hex') + }, + } : undefined + model = extractLua(artifact, head, { releaseRock: releaseRock?.version, localCheckout, matchesExample, declarationSource }) + } else { + model = nativeExtractors[port](artifact, head) + } if (port === 'raku') { // The exporter runs in the library checkout, so its bytes and compiler are part of what the model claims. const producer = model.nativeProvenance.exporter @@ -960,7 +1008,8 @@ for (const [port, cfg] of Object.entries(PORTS)) { }) } } - if (cfg.nativeArtifact) { + // Lua's adapter already verified the cited files against their Git blobs. + if (cfg.nativeArtifact && port !== 'lua') { const locations = model.symbols.flatMap((symbol) => [symbol, ...symbol.signatures.filter((signature) => signature.source)]) for (const entry of locations) { entry.source = { diff --git a/scripts/gen-api-sources.mjs b/scripts/gen-api-sources.mjs index 0c2d56d74..b4a1148b5 100644 --- a/scripts/gen-api-sources.mjs +++ b/scripts/gen-api-sources.mjs @@ -27,7 +27,8 @@ import { execFileSync } from 'node:child_process' import { createHash } from 'node:crypto' import { fileURLToPath } from 'node:url' import { citedFiles } from '../packages/api-model/src/cited-files.ts' -import { checkoutCandidates } from './lib/port-checkout.mjs' +import { isCanonicalPath } from '../packages/api-model/src/products.ts' +import { checkoutCandidates, committedBytes } from './lib/port-checkout.mjs' const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') const DEFAULT_MODELS = join(root, 'site/src/data/api') @@ -37,11 +38,6 @@ const digest = (content) => createHash('sha256').update(content).digest('hex') export { citedFiles } -/** A relative path inside a repository: no escape, no query, no hidden separator. */ -export const isCanonicalPath = (file) => typeof file === 'string' && file !== '' && !file.startsWith('/') - && !/[\\?#%\0\n\r]/.test(file) && !/^[a-z]:/i.test(file) - && file.split('/').every((part) => part !== '' && part !== '.' && part !== '..') - /** Python's workspace manager and MCP server are packages of other repositories. */ const REPO_CHECKOUTS = { 'tmux-python/tmuxp': { variable: 'LIBTMUX_DOCS_WORKSPACE_PY', fallback: '~/work/python/tmuxp' }, @@ -73,10 +69,8 @@ export function checkoutHolding(checkouts, revision) { /** Committed text of a file at a revision, or undefined when the revision has no such text file. */ export function committedText(checkout, revision, file) { - try { - const content = git(checkout, 'show', `${revision}:${file}`) - return content.includes('\0') || content.includes('�') ? undefined : content - } catch { return undefined } + const text = committedBytes(checkout, revision, file)?.toString('utf8') + return text === undefined || text.includes('\0') || text.includes('�') ? undefined : text } /** A cached entry that still describes its bytes and names the revision asked for. */ diff --git a/scripts/gen-api-sources.negative.mjs b/scripts/gen-api-sources.negative.mjs index 19461b380..63240fe66 100644 --- a/scripts/gen-api-sources.negative.mjs +++ b/scripts/gen-api-sources.negative.mjs @@ -5,7 +5,8 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'nod import { tmpdir } from 'node:os' import { join } from 'node:path' import { execFileSync } from 'node:child_process' -import { citedFiles, isCanonicalPath, run } from './gen-api-sources.mjs' +import { isCanonicalPath } from '../packages/api-model/src/products.ts' +import { citedFiles, run } from './gen-api-sources.mjs' const scratch = mkdtempSync(join(tmpdir(), 'libtmux-api-source-cache-')) const modelsDir = join(scratch, 'models') @@ -82,6 +83,11 @@ try { // A build that regenerated the model at a later revision must replace the copies, not keep the committed ones. const later = checkoutGit('rev-parse', 'HEAD') + checkoutGit('replace', revision, later) + quietly(() => run(options({ check: true }))) + checkoutGit('replace', '-d', revision) + console.log('ok a local replacement ref keeps the published source at the original revision') + const rebased = { ...model, revision: later, symbols: model.symbols.map((symbol) => ({ ...symbol, source: { ...symbol.source, line: 4 } })) } writeFileSync(join(modelsDir, 'go.json'), JSON.stringify(rebased)) assert.throws(() => quietly(() => run(options({ check: true }))), /differs/) diff --git a/scripts/lib/port-checkout.mjs b/scripts/lib/port-checkout.mjs index 7b538bb46..3df072411 100644 --- a/scripts/lib/port-checkout.mjs +++ b/scripts/lib/port-checkout.mjs @@ -12,10 +12,20 @@ * 2. For a core port, the override of a wrapper that shares its repository. * 3. The port's ports.ts `worktree` and `checkout`, in the order the caller asks for. */ +import { execFileSync } from 'node:child_process' import { homedir } from 'node:os' import { join } from 'node:path' import { PORTS } from '../../site/src/lib/ports.ts' +/** Read a file as a link to that revision on GitHub will show it. */ +export function committedBytes(checkout, revision, file) { + try { + return execFileSync('git', ['--no-replace-objects', '-C', checkout, 'show', `${revision}:${file}`], { + maxBuffer: 16 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'], + }) + } catch { return undefined } +} + export const checkoutVariable = (slug) => `LIBTMUX_DOCS_CHECKOUT_${slug.toUpperCase()}` export const expandHome = (path) => (path.startsWith('~/') ? join(homedir(), path.slice(2)) : path) diff --git a/site/src/content/docs/ports/lua/examples/capture-pane-output.md b/site/src/content/docs/ports/lua/examples/capture-pane-output.md index ce5897326..8a83304e5 100644 --- a/site/src/content/docs/ports/lua/examples/capture-pane-output.md +++ b/site/src/content/docs/ports/lua/examples/capture-pane-output.md @@ -16,8 +16,10 @@ You need tmux 3.3a or newer and a Unix environment; no existing session is required. Save the program as `capture.lua` and run it after the [setup](#setup-and-run). -The library connects to a running server and does not start one, so the program -starts its own with the `tmux` command and stops it at the end. +This program uses the published `libtmux` 0.1.1-1 rock and starts its private +server with luv. The Lua checkout has a capture example that starts and stops +the server with the SCM rock. +[Checkout setup and examples](https://github.com/libtmux/libtmux-lua/blob/d8266f22bb7ddace64b597fc35899ab72c71cf9f/examples/api/README.md). ## Read what's on screen diff --git a/site/src/content/docs/ports/lua/guides/attaching-to-tmux.md b/site/src/content/docs/ports/lua/guides/attaching-to-tmux.md index 5d8991b90..3a481adbd 100644 --- a/site/src/content/docs/ports/lua/guides/attaching-to-tmux.md +++ b/site/src/content/docs/ports/lua/guides/attaching-to-tmux.md @@ -27,9 +27,9 @@ existing server, and `print_work` connects a `Server` to it and finds `work`. Without the variable, the program starts a private server of its own in a new temporary directory, creates `work` with [`Server:new_session`](../../reference/libtmux-server-new_session/), and -connects a second `Server` to that socket by path. The library connects to a -running server and does not start one, so the program has `tmux` start the -daemon. It stops the private server with +connects a second `Server` to that socket by path. This program uses the +published `libtmux` 0.1.1-1 rock and starts the daemon with luv. It stops the +private server with [`Server:command`](../../reference/libtmux-server-command/) and removes the directory after success or failure. If the server does not stop, the program reports the error and keeps the directory. @@ -154,6 +154,13 @@ The program prints `work`. To use an existing server of your own, set `LIBTMUX_SOCKET_PATH` to its socket before running the program; it prints `work` and leaves that server running. +The checkout's `connect.lua` starts a private tmux server, reads its session +through a second handle, prints `connected`, and stops the server. Install the +SCM rock to run it. See [`Runtime:start_server`](https://github.com/libtmux/libtmux-lua/blob/d8266f22bb7ddace64b597fc35899ab72c71cf9f/examples/api/connect.lua#L14) +and [`OwnedServer:stop`](https://github.com/libtmux/libtmux-lua/blob/d8266f22bb7ddace64b597fc35899ab72c71cf9f/examples/api/connect.lua#L27) +in the complete program. +[Checkout setup and program](https://github.com/libtmux/libtmux-lua/blob/d8266f22bb7ddace64b597fc35899ab72c71cf9f/examples/api/README.md). + ## Find or create a session diff --git a/site/src/lib/versions.ts b/site/src/lib/versions.ts index ed64357e9..3d8dd08b6 100644 --- a/site/src/lib/versions.ts +++ b/site/src/lib/versions.ts @@ -306,7 +306,26 @@ export function buildTarget(env: Record) { const version = env.LIBTMUX_DOCS_VERSION ?? 'latest' const kind = (env.LIBTMUX_DOCS_VERSION_KIND ?? 'trunk') as VersionKind const isDefault = env.LIBTMUX_DOCS_IS_DEFAULT === 'true' - return { version, kind, isDefault } + const resolvesTo = env.LIBTMUX_DOCS_RESOLVES_TO + return { version, kind, isDefault, ...(resolvesTo ? { resolvesTo } : {}) } +} + +/** The numbered Lua rock that matches a tag or an alias to a tag. */ +export function releaseRockForBuild( + build: { version: string; kind: VersionKind; resolvesTo?: string }, + declared: string | undefined, +): { tag: string; version: string } | undefined { + const slug = build.kind === 'tag' ? build.version : build.kind === 'alias' ? build.resolvesTo : undefined + if (!slug) return undefined + const tag = releaseTag(slug, { tagGrammar: 'luarocks' }) + if (!tag && build.kind === 'alias') return undefined + if (!tag || typeof declared !== 'string') throw new Error('Lua release build requires a numbered rock version') + const expected = tag.startsWith('v') ? tag : `v${tag}` + const rock = packageVersion(declared, 'luarocks') + if (rock.tag !== expected || rock.revision < 1 || declared.startsWith('v')) { + throw new Error(`Lua rock version ${declared} does not match release tag ${slug}`) + } + return { tag: expected, version: declared } } /** diff --git a/site/test/versions.test.ts b/site/test/versions.test.ts index cbf2f1ede..8ff8ac1f1 100644 --- a/site/test/versions.test.ts +++ b/site/test/versions.test.ts @@ -5,12 +5,14 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { + buildTarget, comparePackageVersions, compareTags, newestPublishedTag, packageVersionIsPrerelease, parseTag, registryVersion, + releaseRockForBuild, releaseTag, selectBuildVersions, sortVersions, @@ -447,3 +449,29 @@ describe('registryVersion', () => { expect(registryVersion(next, undefined, ['0.1.0'], rust)).toBe('latest') }) }) + +describe('releaseRockForBuild', () => { + it.each(['0.1.1', '0.1.0alpha4', '0.1.0beta2', '0.1.0rc1'])('keeps the matching rock revision for tag %s', (version) => { + const build = buildTarget({ LIBTMUX_DOCS_VERSION_KIND: 'tag', LIBTMUX_DOCS_VERSION: `v${version}` }) + expect(releaseRockForBuild(build, `${version}-1`)).toEqual({ tag: `v${version}`, version: `${version}-1` }) + }) + + it('uses the alias target when latest points to a tag', () => { + const build = buildTarget({ + LIBTMUX_DOCS_VERSION_KIND: 'alias', LIBTMUX_DOCS_VERSION: 'latest', LIBTMUX_DOCS_RESOLVES_TO: 'v0.1.1', + }) + expect(releaseRockForBuild(build, '0.1.1-1')).toEqual({ tag: 'v0.1.1', version: '0.1.1-1' }) + expect(releaseRockForBuild({ ...build, resolvesTo: 'latest' }, '0.1.1-1')).toBeUndefined() + }) + + it.each(['trunk', 'branch', 'pr'] as const)('builds from source for %s even when the manifest declares a rock', (kind) => { + expect(releaseRockForBuild({ kind, version: 'v0.1.1' }, '0.1.1-1')).toBeUndefined() + }) + + it('rejects stale package metadata or an unnumbered rock on a release page', () => { + const build = { kind: 'tag' as const, version: 'v0.1.1' } + for (const rock of ['0.1.0-1', '0.1.1', 'scm-1']) { + expect(() => releaseRockForBuild(build, rock)).toThrow(/does not match release tag v0\.1\.1/) + } + }) +})