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
37 changes: 33 additions & 4 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,21 @@ extension is changed when a file in its folder differs from its last `<id>@*` ta
number, not the push range, so a run the concurrency group dropped is caught up), when it has no
such tag yet, or when that tag has no `agentage-extension.json` record (a release that failed after
its tag). Only the folder is read: each extension keeps its own `package-lock.json` there, and a
change to a shared root file (a root lock, a workflow, a config) does not release anything. When
change to a shared root file (a root lock, a workflow, a config) does not release anything.

Some files at the folder root never release an extension on their own: `/*.md`, `/docs/**`,
`/.github/**`, `/.repo-doctor.yml`, `/.gitignore`, `/.prettierrc*`, `/.editorconfig` and `/LICENSE`.
Each is anchored at the root: a deeper `.md` or `docs/` (a blog post a site serves) counts. A
`.release-ignore` file in the extension folder adds patterns (gitignore style, one per line, `#`
starts a comment, a pattern with no `/` matches at any depth, the last matching line wins) and a
`!pattern` line re-includes one. What goes into the image always counts, whatever a pattern says:
`package.json`, `package-lock.json`, `src/**` and `Dockerfile*` at the folder root (so a
Dependabot bump of the lock releases). A rename counts as two paths. An extension is changed only
when at least one changed file counts; the `changed:` line names the first 5 of them (`in a.js,
b.js`), and the `unchanged:` line names the ignored files when only those changed (`only ignored
files changed: README.md`). `--dry-run` prints the same lines.

When
the last tag is on this commit (a re-run), that version is resumed. An extension is refused (a
`FAIL history:` line) when the commit of its last tag is not an ancestor of this commit: a re-run
of an older run never gives older code a higher version. It is refused (`FAIL stuck:`, naming the
Expand All @@ -573,11 +587,26 @@ that UTC day. The version and `repository` (the releasing repo, which the
The build allows only those files to differ from `HEAD`. Then the tag `<id>@<version>` is created
on the commit (a tag on another commit is refused), before the build, so a failed build uses up its
`N`. The guard and images are as above; npm is published before the records are attached, so a
version with a record is on npm (a private package skips npm). When npm fails, no record goes up:
version with a record is on npm, unless npm was skipped (a private package, or a private repo, see
below). When npm fails, no record goes up:
a re-run of that commit is refused by the guard (images pushed, no record), and the next commit
takes a new `N`. The release is created with `--target <commit>`. Every changed extension is tried:
one that fails or is refused does not stop the others. The run ends with one table (`id`,
`version`, `result`: `released`, `failed`, `refused` or `unchanged`) and exits 1 when any failed
one that fails or is refused does not stop the others.

A private repo never puts its source on public npm by accident. Before the tag, a package that is
not `"private": true` reads `gh api repos/<owner>/<repo> --jq .private`: only `false` publishes.
When the repo is private, npm is skipped unless `package.json` opts in with both
`publishConfig.access` set to `"public"` and the top-level `"agentagePublishFromPrivateRepo": true`
(top level: the kit refuses unknown keys under `agentage`); an answer that is not `true` or
`false`, or a call that fails, fails that extension before its tag (`FAIL npm: cannot read whether
<repo> is private`, exit 1); the next run retries with the same `N`. A skip prints one `AMBER npm: ...`
line, the images and records still go out, the row reads `released, AMBER: npm skipped`,
`published` is `false` and it alone does not make the exit code non-zero. A re-run of that commit
resumes the version and reads the visibility again. The release without `--changed` (a `v*` tag)
has no such check.

The run ends with one table (`id`,
`version`, `result`: `released`, `released, AMBER: npm skipped`, `failed`, `refused` or `unchanged`) and exits 1 when any failed
or was refused; the error names each one as `<id>: FAIL ...` and keeps the code of the first. `--dry-run` prints the plan and writes, tags, pushes and publishes nothing (a refused extension
still exits 1); without
`--changed` it is refused with `invalid_argument` (exit 1).
Expand Down
129 changes: 129 additions & 0 deletions src/commands/extension/release-changed-ignore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { describe, expect } from 'vitest';
import { test } from '../../test/config-dir.js';
import { ciClone, makeRepo, release, writeExtension, type Repo } from '../../test/release-repo.js';

// One extension at `rel`, released from the first commit; `files` then change on a second.
const changedAfterTag = (rel: string, files: string[], ignoreFile?: string) => {
const repo = makeRepo();
writeExtension(repo, rel, 'probe');
const at = (f: string) => (rel === '.' ? f : `${rel}/${f}`);
if (ignoreFile !== undefined) repo.write(at('.release-ignore'), ignoreFile);
const first = repo.commit('base');
repo.tag('probe@2026.1121.1');
for (const f of files) repo.write(at(f), `changed ${f}\n`);
repo.commit('change');
return { repo, records: { 'probe@2026.1121.1': first } };
};

const plan = async (repo: Repo, records: Record<string, string>) =>
release({ dir: ciClone(repo), w: { records }, opts: { dryRun: true } });

const CHANGED = 'PASS changed: probe (.) differs from probe@2026.1121.1 in';

describe('extension release --changed: files that do not release', () => {
test('root layout: only the workflow, docs and markdown changed: nothing is released', async () => {
const files = ['.github/workflows/release.yml', 'README.md', 'docs/guide.txt'];
const { repo, records } = changedAfterTag('.', files);
const run = await release({ dir: ciClone(repo), w: { records } });
expect(run.error).toBeNull();
expect(run.lines).toContain(
'PASS unchanged: probe (.) is the same as probe@2026.1121.1; only ignored files changed: .github/workflows/release.yml, README.md, docs/guide.txt'
);
expect(run.result).toEqual({ released: [], unchanged: ['probe'] });
expect(run.calls.some((c) => c.includes('/git/refs'))).toBe(false);
});

test('the defaults hold at the folder root only: deeper markdown and docs count', async () => {
const deeper = ['site/public/README.md', 'site/src/content/x.md', 'sub/docs/a.md'];
const { repo, records } = changedAfterTag('.', ['README.md', 'docs/a.md', ...deeper]);
const run = await plan(repo, records);
expect(run.lines).toContain(`${CHANGED} ${deeper.join(', ')}: release probe@2026.1122.1`);
});

test('a name with a space and a non-ASCII letter is read exactly', async () => {
const quiet = changedAfterTag('.', ['naïve notes.md']);
expect((await plan(quiet.repo, quiet.records)).lines).toContain(
'PASS unchanged: probe (.) is the same as probe@2026.1121.1; only ignored files changed: naïve notes.md'
);
const { repo, records } = changedAfterTag('.', ['site/naïve page.md']);
const run = await plan(repo, records);
expect(run.lines).toContain(`${CHANGED} site/naïve page.md: release probe@2026.1122.1`);
});

test('a Dependabot bump of the lock releases: package files always count', async () => {
const { repo, records } = changedAfterTag('.', ['package-lock.json', '.github/dependabot.yml']);
const run = await plan(repo, records);
expect(run.lines).toContain(`${CHANGED} package-lock.json: release probe@2026.1122.1`);
});

test('.release-ignore adds patterns, but never over src/** or Dockerfile*', async () => {
const ignore = '# local notes\n\nnotes.txt\nsrc/**\nDockerfile*\n';
const files = ['notes.txt', 'src/a.ts', 'Dockerfile'];
const { repo, records } = changedAfterTag('.', files, ignore);
const run = await plan(repo, records);
expect(run.lines).toContain(`${CHANGED} Dockerfile, src/a.ts: release probe@2026.1122.1`);
const only = changedAfterTag('.', ['notes.txt'], ignore);
const quiet = await plan(only.repo, only.records);
expect(quiet.lines).toContain(
'PASS unchanged: probe (.) is the same as probe@2026.1121.1; only ignored files changed: notes.txt'
);
});

test('a !pattern line re-includes a default', async () => {
const { repo, records } = changedAfterTag('.', ['README.md'], '!README.md\n');
const run = await plan(repo, records);
expect(run.lines).toContain(`${CHANGED} README.md: release probe@2026.1122.1`);
});

test('more than five files: the first five, then how many more', async () => {
const files = ['a.js', 'b.js', 'c.js', 'd.js', 'e.js', 'f.js', 'g.js', 'h.md'];
const { repo, records } = changedAfterTag('.', files);
const run = await plan(repo, records);
expect(run.lines).toContain(
`${CHANGED} a.js, b.js, c.js, d.js, e.js and 2 more: release probe@2026.1122.1`
);
});

test('extensions/<name>: patterns read the folder; a markdown-only change stays', async () => {
const repo = makeRepo();
writeExtension(repo, 'extensions/probe', 'probe');
writeExtension(repo, 'extensions/fixture', 'fixture');
const first = repo.commit('two');
repo.tag('probe@2026.1121.1');
repo.tag('fixture@2026.1121.1');
repo.write('extensions/probe/docs/guide.md', 'docs\n');
repo.write('extensions/probe/index.js', 'code\n');
repo.write('extensions/fixture/CHANGELOG.md', 'notes\n');
repo.commit('change');
const run = await plan(repo, { 'probe@2026.1121.1': first, 'fixture@2026.1121.1': first });
expect(run.lines).toContain(
'PASS changed: probe (extensions/probe) differs from probe@2026.1121.1 in index.js: release probe@2026.1122.1'
);
expect(run.lines).toContain(
'PASS unchanged: fixture (extensions/fixture) is the same as fixture@2026.1121.1; only ignored files changed: CHANGELOG.md'
);
});

test('a move from src/ to docs/ still releases: renames are two paths', async () => {
const repo = makeRepo();
writeExtension(repo, '.', 'probe');
repo.write('src/long-enough.ts', 'export const a = 1;\n'.repeat(20));
const first = repo.commit('base');
repo.tag('probe@2026.1121.1');
repo.write('docs/keep.txt', 'a folder to move into\n');
repo.commit('docs');
repo.git('mv', 'src/long-enough.ts', 'docs/long-enough.md');
repo.commit('move');
expect(repo.git('diff', '-M', '--name-status', 'HEAD~1', 'HEAD')).toMatch(/^R/);
const run = await plan(repo, { 'probe@2026.1121.1': first });
expect(run.lines).toContain(`${CHANGED} src/long-enough.ts: release probe@2026.1122.1`);
});

test('only ignored files, but the last tag has no record: released with a new N', async () => {
const { repo } = changedAfterTag('.', ['README.md']);
const run = await plan(repo, {});
expect(run.lines).toContain(
'PASS changed: probe (.) equals probe@2026.1121.1, which has no record: release probe@2026.1122.1'
);
});
});
94 changes: 94 additions & 0 deletions src/commands/extension/release-changed-npm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { describe, expect } from 'vitest';
import { test } from '../../test/config-dir.js';
import {
ciClone,
makeRepo,
pkgOf,
release,
REPO,
writeExtension,
type World,
} from '../../test/release-repo.js';

const VISIBILITY = `gh api repos/${REPO} --jq .private`;

// One public-npm extension (no "private": true) at the root, with extra package.json fields.
const publicPackage = (extra: Record<string, unknown> = {}) => {
const repo = makeRepo();
repo.write('package.json', `${JSON.stringify({ ...pkgOf('probe'), ...extra }, null, 2)}\n`);
repo.write('index.js', 'export {};\n');
repo.commit('one');
return ciClone(repo);
};

const npmCalls = (calls: string[]) => calls.filter((c) => c.startsWith('npm'));

const skipped = async (w: World, extra?: Record<string, unknown>) => {
const run = await release({ dir: publicPackage(extra), w });
expect(run.error).toBeNull();
expect(npmCalls(run.calls)).toEqual([]);
expect(run.calls.filter((c) => c.startsWith('gh release create'))).toHaveLength(1);
expect(run.lines.slice(-2)).toEqual([
'id version result',
'probe 2026.1122.1 released, AMBER: npm skipped',
]);
expect(run.result).toMatchObject({ released: [{ published: false, built: true }] });
return run.lines.filter((l) => l.startsWith('AMBER'));
};

describe('extension release --changed: npm from a private repo', () => {
test('a public repo publishes as before', async () => {
const run = await release({ dir: publicPackage() });
expect(run.calls).toContain(VISIBILITY);
expect(run.calls).toContain('npm publish --access public --provenance --ignore-scripts');
});

test('a private repo: npm is skipped with one AMBER line; images and record go out', async () => {
expect(await skipped({ visibility: 'true' })).toEqual([
`AMBER npm: ${REPO} is a private repo: npm skipped; set publishConfig.access to "public" and agentagePublishFromPrivateRepo to true to publish it`,
]);
});

test('half an opt-in is no opt-in', async () => {
const only = { publishConfig: { access: 'public' } };
expect(await skipped({ visibility: 'true' }, only)).toHaveLength(1);
expect(
await skipped({ visibility: 'true' }, { agentagePublishFromPrivateRepo: true })
).toHaveLength(1);
});

test('both opt-in fields publish from a private repo', async () => {
const extra = { publishConfig: { access: 'public' }, agentagePublishFromPrivateRepo: true };
const run = await release({ dir: publicPackage(extra), w: { visibility: 'true' } });
expect(run.error).toBeNull();
expect(run.lines).toContain(
`PASS npm: ${REPO} is private, @agentage/extension-probe opts in to public npm`
);
expect(run.calls).toContain('npm publish --access public --provenance --ignore-scripts');
});

test('a visibility that cannot be read fails that extension before its tag: exit 1', async () => {
const cases: [World['visibility'], string][] = [
[{ ok: false, out: '', err: 'HTTP 502' }, 'HTTP 502'],
['', 'no answer'],
['null', 'null'],
];
for (const [visibility, why] of cases) {
const run = await release({ dir: publicPackage(), w: { visibility } });
expect(run.code).toBe('release_refused');
expect(run.error).toBe(`probe: FAIL npm: cannot read whether ${REPO} is private (${why})`);
expect(run.calls.filter((c) => c.includes('/git/refs') || c.startsWith('npm'))).toEqual([]);
expect(run.lines.at(-1)).toBe('probe 2026.1122.1 failed');
}
});

test('a "private": true package never reads the visibility', async () => {
const repo = makeRepo();
writeExtension(repo, '.', 'probe', { private: true });
repo.commit('one');
const run = await release({ dir: ciClone(repo), w: { visibility: 'true' } });
expect(run.error).toBeNull();
expect(run.calls).not.toContain(VISIBILITY);
expect(run.lines).not.toContain(expect.stringMatching(/^AMBER/));
});
});
2 changes: 1 addition & 1 deletion src/commands/extension/release-changed-safety.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('extension release --changed: tags with no record', () => {
const run = await release({ dir: ciClone(failedTags(2)), opts: { dryRun: true } });
expect(run.error).toBeNull();
expect(run.lines).toContain(
'PASS changed: probe (extensions/probe) differs from probe@2026.1122.2: release probe@2026.1122.3'
'PASS changed: probe (extensions/probe) differs from probe@2026.1122.2 in index.js: release probe@2026.1122.3'
);
});

Expand Down
7 changes: 4 additions & 3 deletions src/commands/extension/release-changed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('extension release --changed: what it releases', () => {
expect(run.lines).toEqual([
`PASS master: ${run.sha} is on master`,
'PASS unchanged: fixture (extensions/fixture) is the same as fixture@2026.1121.1',
'PASS changed: probe (extensions/probe) differs from probe@2026.1121.1: release probe@2026.1122.1',
'PASS changed: probe (extensions/probe) differs from probe@2026.1121.1 in index.js: release probe@2026.1122.1',
'PASS dry run: would release probe@2026.1122.1; nothing was written, tagged, pushed or published',
]);
expect(run.calls).toEqual([
Expand All @@ -73,6 +73,7 @@ describe('extension release --changed: what it releases', () => {
expect(run.error).toBeNull();
const tag = 'probe@2026.1122.1';
expect(run.calls.filter((c) => !c.includes('2026.1121.1'))).toEqual([
`gh api repos/${REPO} --jq .private`,
'npm --version',
`gh api repos/${REPO}/git/refs -f ref=refs/tags/${tag} -f sha=${run.sha}`,
`gh release download ${tag} -R ${REPO} -p agentage-extension.json -O -`,
Expand Down Expand Up @@ -119,7 +120,7 @@ describe('extension release --changed: what it releases', () => {
repo.commit('readme only');
const run = await release({ dir: ciClone(repo), w: { records }, opts: { dryRun: true } });
expect(run.lines).toContain(
'PASS changed: probe (extensions/probe) differs from probe@2026.1121.1: release probe@2026.1122.1'
'PASS changed: probe (extensions/probe) differs from probe@2026.1121.1 in index.js: release probe@2026.1122.1'
);
});

Expand All @@ -140,7 +141,7 @@ describe('extension release --changed: what it releases', () => {
const run = await release({ dir });
expect(run.error).toBeNull();
expect(run.lines[1]).toBe(
'PASS changed: root (.) differs from root@2026.1121.1: release root@2026.1122.1'
'PASS changed: root (.) differs from root@2026.1121.1 in index.js: release root@2026.1122.1'
);
expect(run.lines).toContain('PASS npm: private package, not published');
expect(run.calls.some((c) => c.startsWith('npm'))).toBe(false);
Expand Down
Loading