Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/api-model/src/languages/swift-examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ describe('complete Swift API examples', () => {
`https://github.com/${source.repo}/blob/${source.revision}/Examples/Sources/ApiServer/ApiServer.swift`)
})

it('depends on a final release with from:, the range the package README recommends', () => {
const { read, files } = fixture()
files['Sources/LibTmux/LibTmuxVersion.swift'] =
'public enum LibTmuxVersion {\n public static let current = "0.1.0"\n}\n'
const target = symbol()
attachCompleteSwiftExamples([target], read, source)
const packageBlock = target.doc?.examples?.[1]
expect(packageBlock?.code).toContain(
'.package(url: "https://github.com/libtmux/libtmux-swift.git", from: "0.1.0")')
expect(packageBlock?.code).not.toContain('exact:')
expect(packageBlock?.intro).toContain('from release 0.1.0')
})

it('leaves older source revisions without a manifest unchanged', () => {
const target = symbol()
const original = structuredClone(target)
Expand Down
12 changes: 8 additions & 4 deletions packages/api-model/src/languages/swift-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ interface SwiftExamples {
*
* The port's consumer package depends on a checkout by path; readers get the
* same package depending on the repository at the release the documented
* revision declares, which moves only in release commits. `exact:` is the
* only requirement SwiftPM resolves for a prerelease.
* revision declares, which moves only in release commits. A final release
* takes `from:`, the range the package README recommends; a prerelease takes
* `exact:`, the only requirement SwiftPM resolves for one.
*/
export function attachCompleteSwiftExamples(
symbols: ApiSymbol[],
Expand Down Expand Up @@ -56,8 +57,11 @@ export function attachCompleteSwiftExamples(
const pathDependency = '.package(name: "libtmux", path: "libtmux-source")'
require(localPackage.split(pathDependency).length === 2 && localPackage.includes('package: "libtmux")'),
'consumer package must depend on the checkout by path')
const prerelease = release!.includes('-')
const requirement = prerelease ? `exact: "${release}"` : `from: "${release}"`
const fetched = prerelease ? `at release ${release}` : `from release ${release}`
const packageCode = localPackage
.replace(pathDependency, `.package(url: "https://github.com/${source.repo}.git", exact: "${release}")`)
.replace(pathDependency, `.package(url: "https://github.com/${source.repo}.git", ${requirement})`)
.replaceAll('package: "libtmux")', `package: "${source.repo.split('/')[1]}")`)
const names = new Set<string>()
const targets = new Set<string>()
Expand All @@ -79,7 +83,7 @@ export function attachCompleteSwiftExamples(
const blocks: NonNullable<DocBlock['examples']> = [
{
lang: 'swift',
intro: `${example.title}. ${example.description.replace(/\n/g, ' ')} Use Swift ${tools} or newer and tmux 3.3a or newer on Linux or macOS. In an empty directory, save this consumer package as \`Package.swift\`; SwiftPM fetches the library at release ${release}:`,
intro: `${example.title}. ${example.description.replace(/\n/g, ' ')} Use Swift ${tools} or newer and tmux 3.3a or newer on Linux or macOS. In an empty directory, save this consumer package as \`Package.swift\`; SwiftPM fetches the library ${fetched}:`,
code: packageCode,
},
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ $ node scripts/gen-registry.mjs
```

Regenerates `site/src/data/registry.json`, which records what each port's
package registry carries right now: a stable release, a prerelease only, or
package registry carries right now: a final release, a prerelease only, or
nothing at all. `installCommand` in
[ports.ts](../site/src/lib/ports.ts) composes that with the install spellings
to produce the command a page or an agent prompt shows, so the command cannot
name a version the registry does not have.

It matters because most ports have no stable release, and several
It matters because a port with only prereleases is common, and several
resolve nothing unless the prerelease is named: Cargo treats an alpha as out of
range for a plain requirement, `go get` without a version resolves the highest
release and a prerelease is not one, and SwiftPM's `from:` excludes prereleases
Expand Down
53 changes: 29 additions & 24 deletions scripts/gen-registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
*
* The agent prompts name an install command, and an install command that does
* not resolve is worse than no prompt at all: the reader's agent runs it,
* fails, and starts inventing. Seven of the eight ports have no stable release
* and one is not published at all, so the right spelling differs per port and
* changes the day any of them ships.
* fails, and starts inventing. A port with only prereleases needs a different
* spelling from one with a final release, and one port is not published at
* all, so the right spelling differs per port and changes the day one ships.
*
* Two spellings are forced rather than chosen, and the rest are pinned so a
* prompt's prose and its command agree:
*
* - Swift tags only prereleases, and `0.1.0-alpha.4` sorts below `0.1.0`, so
* `from: "0.1.0"` has nothing in range. `exact:` is the only form.
* - A Swift prerelease such as `0.1.0-alpha.4` sorts below `0.1.0`, so
* `from:` never selects one. `exact:` is the only form for a prerelease;
* a final release takes `from:`.
* - C++ has no vcpkg port, so a CMake FetchContent block at a tag is the
* only way in.
*
Expand All @@ -21,9 +22,9 @@
* pin, because a resolver with no release to prefer falls back to a
* prerelease. The pins stay because the prompt names a version in prose beside
* the command, and because a bare command changes what it installs the day a
* stable lands while a generated pin changes visibly.
* release lands while a generated pin changes visibly.
*
* So which of `installForms.{stable,prerelease,git}` applies is a fact about
* So which of `installForms.{release,prerelease,git}` applies is a fact about
* the registry today, not about the port, and it belongs in generated data
* rather than in a hand-typed string that goes stale the next time anyone
* publishes. `ports.ts` owns the spellings; this owns the state.
Expand Down Expand Up @@ -84,7 +85,7 @@
* written for git tags. Registries mostly report the bare number: crates.io
* says `0.1.0-alpha.10`, Maven Central says `0.0.1-alpha.10`, PyPI says
* `0.62.0`, and only the Go proxy says `v0.0.1-alpha.6`. Parsing a bare
* number with those regexes returns null, which would classify every stable
* number with those regexes returns null, which would classify every final
* release as unpublished. Normalise first, once, here.
*/
/** Whether a version string is a prerelease under this port's grammar. */
Expand All @@ -96,10 +97,12 @@
const newestFirst = (versions, grammar) =>
[...versions].sort((a, b) => comparePackageVersions(a, b, grammar))

/** The release stage a PyPI project declares in its Development Status classifier. */
const PYPI_STAGES = {
'2 - Pre-Alpha': 'pre-alpha', '3 - Alpha': 'alpha', '4 - Beta': 'beta', '5 - Production/Stable': 'stable', '6 - Mature': 'stable',
}
/**
* The prerelease stage a PyPI project declares in its Development Status
* classifier. A later classifier declares nothing here: a final release is
* named by its version's series, never by a claim of stability.
*/
const PYPI_STAGES = { '2 - Pre-Alpha': 'pre-alpha', '3 - Alpha': 'alpha', '4 - Beta': 'beta' }
const declaredStage = (classifiers) => PYPI_STAGES[
classifiers?.find((entry) => entry.startsWith('Development Status :: '))?.slice('Development Status :: '.length)
]
Expand Down Expand Up @@ -188,7 +191,7 @@
} else if (current && /^git-tree-sha1\s*=\s*"[a-f0-9]{40}"$/.test(line)) {
current.tree = true
} else if (current && /^yanked\s*=\s*(true|false)$/.test(line)) {
current.yanked = /true$/.test(line)

Check warning on line 194 in scripts/gen-registry.mjs

View workflow job for this annotation

GitHub Actions / test

unicorn(prefer-string-starts-ends-with)

scripts/gen-registry.mjs:194:24: Prefer String#endsWith over a regex with a dollar sign.
} else {
throw new Error('General: invalid version table')
}
Expand Down Expand Up @@ -358,13 +361,13 @@
/** Classify one port from the versions its registry carries. */
function classify(port, versions, tag) {
if (versions === null || versions.length === 0) {
return { status: 'unpublished', version: null, stable: null, tag }
return { status: 'unpublished', version: null, release: null, tag }
}
const ordered = newestFirst(versions, port.tagGrammar)
const stable = ordered.find((v) => !isPrerelease(v, port.tagGrammar)) ?? null
return stable
? { status: 'stable', version: stable, stable, tag }
: { status: 'prerelease', version: ordered[0], stable: null, tag }
const release = ordered.find((v) => !isPrerelease(v, port.tagGrammar)) ?? null
return release
? { status: 'release', version: release, release, tag }
: { status: 'prerelease', version: ordered[0], release: null, tag }
}

const opts = parseArgs(process.argv.slice(2))
Expand All @@ -378,12 +381,14 @@
* port may not be published yet, so fill only missing entries from the seed.
* Reading --out alone would leave a fresh output path without any fallback.
*/
const seed = existsSync(DEFAULT_OUT)
? JSON.parse(readFileSync(DEFAULT_OUT, 'utf8'))
: existsSync(opts.out)
? JSON.parse(readFileSync(opts.out, 'utf8'))
: { ports: {} }
const baseline = opts.baseline ? JSON.parse(readFileSync(opts.baseline, 'utf8')) : seed
const SCHEMA = 2
/** A file written under another schema is no fallback: its entries name other fields. */
const read = (path) => {
const data = JSON.parse(readFileSync(path, 'utf8'))
return data.schema === SCHEMA ? data : { ports: {} }
}
const seed = existsSync(DEFAULT_OUT) ? read(DEFAULT_OUT) : existsSync(opts.out) ? read(opts.out) : { ports: {} }
const baseline = opts.baseline ? read(opts.baseline) : seed
const committed = { ports: { ...seed.ports, ...baseline.ports } }

const ports = {}
Expand Down Expand Up @@ -457,7 +462,7 @@
}

const payload = {
schema: 1,
schema: SCHEMA,
/**
* Deliberately not a timestamp of this run. A field that changes on every
* invocation makes `--check` fail for no reason and turns a no-op refresh
Expand Down
20 changes: 13 additions & 7 deletions scripts/gen-registry.negative.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ for (const [name, mutate] of mutations) {
const baseline = structuredClone(seed)
delete baseline.ports.powershell
delete baseline.ports.julia
baseline.ports.csharp = { status: 'stable', version: '1.2.3', stable: '1.2.3', tag: 'v1.2.3' }
baseline.ports.csharp = { status: 'release', version: '1.2.3', release: '1.2.3', tag: 'v1.2.3' }
writeFileSync(join(dir, 'published.json'), JSON.stringify(baseline))
writeFileSync(join(dir, 'fetch.mjs'), `
import { readFileSync } from 'node:fs'
Expand Down Expand Up @@ -161,10 +161,16 @@ for (const [name, mutate] of mutations) {
check('a package Hex does not carry is unpublished',
unlisted.ports.elixir?.status === 'unpublished' && unlisted.ports.elixir?.version === null, `${JSON.stringify(unlisted.ports.elixir)} ${unlisted.error}`)
check('an unavailable existing port retains its newer published entry', same(result.ports.csharp, baseline.ports.csharp), result.error)
// A published copy written under another schema names other fields, so it is no fallback.
writeFileSync(join(dir, 'published.json'), JSON.stringify({ ...baseline, schema: 1 }))
result = invoke(replies)
check('a baseline under another schema is ignored', same(result.ports.csharp, seed.ports.csharp), `${JSON.stringify(result.ports.csharp)} ${result.error}`)
writeFileSync(join(dir, 'published.json'), JSON.stringify(baseline))
result = invoke(replies)

// The baseline names a tag the repository never published. Tags the
// repository still carries keep their recorded entry; tags it lacks do not.
const staleJulia = { status: 'unpublished', version: null, stable: null, tag: 'v0.1.0-alpha.1' }
const staleJulia = { status: 'unpublished', version: null, release: null, tag: 'v0.1.0-alpha.1' }
writeFileSync(join(dir, 'published.json'), JSON.stringify({ ...baseline, ports: { ...baseline.ports, julia: staleJulia } }))
const julia = 'https://api.github.com/repos/libtmux/libtmux-julia/tags?per_page=100'
result = invoke({ ...replies, [julia]: { body: '[]' }, [general]: { status: 404, body: '404: Not Found' } })
Expand All @@ -184,7 +190,7 @@ for (const [name, mutate] of mutations) {
const unread = (resolved) => {
const count = Object.keys(resolved.ports).length
if (count !== PORTS.length) return [`the resolver wrote ${count} of ${PORTS.length} ports: ${resolved.error}`]
const registry = { schema: 1, ports: resolved.ports }
const registry = { schema: 2, ports: resolved.ports }
return PORTS.flatMap((port) => [
...['core', 'mcp', 'workspace'].filter((product) => product === 'core' || productAvailable(port, product))
.map((product) => [`${port.slug} ${product}`, () => productStatus(port, product, registry)]),
Expand All @@ -204,24 +210,24 @@ for (const [name, mutate] of mutations) {
const notInGeneral = { status: 404, body: '404: Not Found' }
const prereleaseOnly = { body: `["0.1.0-alpha.2"]\ngit-tree-sha1 = "${'c'.repeat(40)}"\n` }
for (const [state, repository, registry, stage] of [
['a final tag General does not carry yet', ['v0.1.0'], notInGeneral, 'stable'],
['a final tag General does not carry yet', ['v0.1.0'], notInGeneral, '0.x'],
['a prerelease tag General does not carry yet', ['v0.1.0-alpha.1'], notInGeneral, 'alpha'],
['a prerelease General carries', ['v0.1.0-alpha.2'], prereleaseOnly, 'alpha'],
['a prerelease General carries beside a final tag it lacks', ['v0.1.0-alpha.2', 'v0.1.0'], prereleaseOnly, 'alpha'],
['no tag and no General package', [], notInGeneral, 'unreleased'],
]) {
result = invoke({ ...replies, [julia]: tagged(...repository), [general]: registry })
const failures = unread(result)
const read = failures.length === 0 ? productStatus(juliaPort, 'core', { schema: 1, ports: result.ports }) : undefined
const read = failures.length === 0 ? productStatus(juliaPort, 'core', { schema: 2, ports: result.ports }) : undefined
check(`every badge reads ${state} as ${stage}`, read === stage, `${read} ${JSON.stringify(failures)}`)
}
result = invoke({ ...replies, [julia]: tagged('v0.1.0'), [general]: notInGeneral })
check('a final tag General does not carry yet is recorded as the live registry recorded it',
same(result.ports.julia, { status: 'unpublished', version: null, stable: null, tag: 'v0.1.0' }), `${JSON.stringify(result.ports.julia)} ${result.error}`)
same(result.ports.julia, { status: 'unpublished', version: null, release: null, tag: 'v0.1.0' }), `${JSON.stringify(result.ports.julia)} ${result.error}`)
// Once the registry lists a release, a newer tag it lacks is not recorded; the support page says so.
result = invoke({ ...replies, [julia]: tagged('v0.1.0-alpha.2', 'v0.1.0'), [general]: prereleaseOnly })
check('a final tag beside a registry that lists only a prerelease is not recorded',
same(result.ports.julia, { status: 'prerelease', version: '0.1.0-alpha.2', stable: null, tag: 'v0.1.0-alpha.2' }), `${JSON.stringify(result.ports.julia)} ${result.error}`)
same(result.ports.julia, { status: 'prerelease', version: '0.1.0-alpha.2', release: null, tag: 'v0.1.0-alpha.2' }), `${JSON.stringify(result.ports.julia)} ${result.error}`)

// The reads above pass only if the read can fail, so name the port and the tag it could not place.
result = invoke({ ...replies, [julia]: tagged('v0.1.0-dev.3'), [general]: notInGeneral })
Expand Down
4 changes: 2 additions & 2 deletions site/scripts/check-dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@ try {
assert.equal(result.redundantHeaderLinks, 0, 'Surface destinations are absent from the header bar')
assert(result.headerControls.every((control) => Math.abs(control.height - result.headerControls[0].height) < 0.1
&& Math.abs(control.top - result.headerControls[0].top) < 0.1), `${path} at ${width}px: header controls align at equal heights`)
// tmux pages document tmux itself, so the libtmux alpha notice is absent there.
if (path.startsWith('tmux/')) assert.equal(result.badgeForeground, null, `${path}: no libtmux alpha notice`)
// tmux pages document tmux itself, so the libtmux release notice is absent there.
if (path.startsWith('tmux/')) assert.equal(result.badgeForeground, null, `${path}: no libtmux release notice`)
else assert.equal(result.badgeForeground, 'rgb(255, 255, 255)', 'Filled badge uses white foreground')
if (width < 1536) assert(result.schemeLabelWidth <= 1, 'Compact color-scheme controls hide their text visually')
assert(result.overflow <= 1, `${path} at ${width}px: page overflow ${result.overflow}px`)
Expand Down
8 changes: 4 additions & 4 deletions site/scripts/check-status-badges.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict'
import { CONCEPT_DESCRIPTION, PICKER_GROUP_SUMMARY, PORT_BY_SLUG, PRODUCT_STATUS_GUIDE, PRODUCT_STATUS_LINE, PRODUCT_STATUS_LINK, productAvailable, productStatus } from '../src/lib/ports.ts'
import { CONCEPT_DESCRIPTION, PICKER_GROUP_SUMMARY, PORT_BY_SLUG, PRODUCT_STATUS_GUIDE, PRODUCT_STATUS_LINK, productStatusLine, productAvailable, productStatus } from '../src/lib/ports.ts'
import registry from '../src/data/registry.json' with { type: 'json' }
import { HOVER_OPEN } from '../src/lib/status-toggletip.ts'

Expand Down Expand Up @@ -128,7 +128,7 @@ async function checkRows(page, picker, slug, where, kind) {
assert(Math.abs(gap - listGap) <= 1, `${where}: the trigger's badge sits ${gap.toFixed(1)}px from its name, the list's ${listGap.toFixed(1)}px`)
}
const description = await picker.locator(':scope > summary').getAttribute('aria-description')
assert.equal(description, PRODUCT_STATUS_LINE[rows[0].status], `${where}: the trigger is described by the short line`)
assert.equal(description, productStatusLine(rows[0].status), `${where}: the trigger is described by the short line`)
}
}

Expand All @@ -142,7 +142,7 @@ async function checkToggletip(page, picker, badge, status, label, where) {
assert.equal((await card.locator('.status-toggletip__title').innerText()).trim(), status, `${where}: the card is titled with the stage`)
const line = (await card.locator('.status-toggletip__line').innerText()).trim()
assert(line.length <= TOGGLETIP_BUDGET, `${where}: the card's line is ${line.length} characters, over the ${TOGGLETIP_BUDGET} budget: "${line}"`)
assert.equal(line, PRODUCT_STATUS_LINE[status], `${where}: the card holds the ${status} line`)
assert.equal(line, productStatusLine(status), `${where}: the card holds the ${status} line`)
assert.equal(await card.getAttribute('role'), 'group', `${where}: the card is a named group`)
assert.equal(await card.getAttribute('aria-label'), `${status}: ${label}`, `${where}: the card names its product`)
const box = await card.boundingBox()
Expand Down Expand Up @@ -296,7 +296,7 @@ export async function checkStatusBadgesFail(browser, base) {
}, /has exactly one status badge/],
['a wrong stage', picker, {
script: () => document.querySelector('.status-toggletip > .status-badge').setAttribute('data-status', 'concept'),
}, /Core Library states alpha/],
}, /Core Library states (?!concept\b)\S+/],
['a badge far from its name', picker, {
css: '.surface-entry > .surface-entry__badge { left: auto !important; right: 2.1rem !important; top: 1.15rem !important; translate: none !important }',
}, /badge sits beside its name/],
Expand Down
Loading
Loading