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
62 changes: 48 additions & 14 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ every image by digest; `extension release` runs this. `--registry <host/owner>`

```bash
agentage extension release # in release.yml, on a v* tag push
agentage extension release --changed # in release.yml, on a push to master
agentage extension release --changed --dry-run # what it would release; changes nothing
```

What an extension's `release.yml` runs after `npm ci` and `npm run verify`, one `PASS <step>:` line
Expand Down Expand Up @@ -529,6 +531,38 @@ stage publish` instead. `GH_TOKEN` (or `GITHUB_TOKEN`) goes only to `gh` and `NP
npm; both leave the environment first, so the image build and npm lifecycle scripts never see
them. A package with `"private": true` skips npm entirely (no `npm --version`, `view` or `publish`) and prints `PASS npm: private package, not published`. Needs git, `docker` and the `gh` CLI, and npm only for a package that is not private. Needs `docker login` to the registry first.

`--changed` is the release of a repo where a merge to master is the release. Run it from the repo
root: the extensions are each `extensions/<name>` with an `agentage` package, or the root package
when there is none. It reads `GITHUB_REPOSITORY` and `GITHUB_SHA` (default: `HEAD`), refuses a
commit not on `origin/master`, then fetches the tags (a default shallow checkout has none). An
extension is changed when a file in its folder differs from its last `<id>@*` tag (the highest by
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
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
tags) when its newest 3 tags have no record: a build that always fails stops taking new tags until
a release of the last tag succeeds or a human removes those tags. A shallow checkout is deepened
(`--unshallow`) for the ancestor check. A changed
extension gets the date version `YYYY.MDD.N`: the UTC year, then month times 100 plus day (5
January is `105`, 22 November `1122`), and `N` one more than the highest `N` tagged for that id
that UTC day. The version and `repository` (the releasing repo, which the
`org.opencontainers.image.source` label and npm provenance read) go into `package.json`, its
`package-lock.json` and the contracts `check --write` writes, in the CI copy only: never committed.
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:
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
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).

## extension up, down and token

```bash
Expand Down Expand Up @@ -915,20 +949,20 @@ from another site, `AGENTAGE_SITE_FQDN=<site> agentage daemon restart`, then ins
A usage error (an unknown flag, a missing argument) exits 2 with no object; with `--json` it
exits 1 with the error object, code `usage`, and the usage line on stderr.

| Command | `data` |
| ----------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `setup` | `{ extensions: [...] }`, the rows as `extension doctor` has them |
| `extension install`, `disable`, `enable`, `configure` | the daemon's row `{ id, version, source, state, enabled, error? }` |
| `extension list` | the daemon's rows; a folder row has `source: "folder"` and `path` |
| `extension list --available` | `[{ id, version }]` from the market; `meta.skipped` is `[{ id, reason }]`; `meta.down` when silent |
| `extension update` | `[{ id, from, to, updated }]` |
| `extension remove` | `{ id, purged }` |
| `update` | `{ installed, status, latest, updated }` |
| `extension create` | `{ id, dir, from, kept, installed, url }` |
| `extension build` | `{ dir, built, contracts, conforms }`; the kit's result for images |
| `extension release` | `{ id, version, tag, built, published }` |
| `extension up`, `down` | `up`: `{ id, version, url, port, stoppedBy }` (`--docker`: `{ lines }`); `down`: `{ local, lines }` |
| `extension token` | `{ token }`; nothing else is printed |
| Command | `data` |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `setup` | `{ extensions: [...] }`, the rows as `extension doctor` has them |
| `extension install`, `disable`, `enable`, `configure` | the daemon's row `{ id, version, source, state, enabled, error? }` |
| `extension list` | the daemon's rows; a folder row has `source: "folder"` and `path` |
| `extension list --available` | `[{ id, version }]` from the market; `meta.skipped` is `[{ id, reason }]`; `meta.down` when silent |
| `extension update` | `[{ id, from, to, updated }]` |
| `extension remove` | `{ id, purged }` |
| `update` | `{ installed, status, latest, updated }` |
| `extension create` | `{ id, dir, from, kept, installed, url }` |
| `extension build` | `{ dir, built, contracts, conforms }`; the kit's result for images |
| `extension release` | `{ id, version, tag, built, published }`; `--changed`: `{ released, unchanged }`, with `--dry-run` `{ dryRun, changed, unchanged }` |
| `extension up`, `down` | `up`: `{ id, version, url, port, stoppedBy }` (`--docker`: `{ lines }`); `down`: `{ local, lines }` |
| `extension token` | `{ token }`; nothing else is printed |

`setup` with `--json` does not open a browser: when it must sign in it needs `--no-browser`, else
it fails with `confirmation_required`. `extension remove --purge` with `--json` needs `--yes`, else
Expand Down
124 changes: 124 additions & 0 deletions src/commands/extension/release-changed-safety.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect } from 'vitest';
import { test } from '../../test/config-dir.js';
import { checkoutAt, ciClone, makeRepo, release, writeExtension } from '../../test/release-repo.js';

const tagged = (calls: string[]) => calls.filter((c) => c.includes('/git/refs'));

// probe changed on C1 (its run failed), then changed again and released on C2.
const oldAndNew = () => {
const repo = makeRepo();
writeExtension(repo, 'extensions/probe', 'probe');
repo.commit('base');
repo.tag('probe@2026.1121.1');
const base = repo.git('rev-parse', 'HEAD');
repo.write('extensions/probe/index.js', 'c1\n');
writeExtension(repo, 'extensions/fixture', 'fixture');
const c1 = repo.commit('c1');
repo.write('extensions/probe/index.js', 'c2\n');
const c2 = repo.commit('c2');
repo.tag('probe@2026.1122.1');
return { repo, c1, records: { 'probe@2026.1121.1': base, 'probe@2026.1122.1': c2 } };
};

// probe tagged `count` times today with no record, then changed again.
const failedTags = (count: number) => {
const repo = makeRepo();
writeExtension(repo, 'extensions/probe', 'probe');
repo.commit('base');
for (let n = 1; n <= count; n++) {
repo.tag(`probe@2026.1122.${n}`);
repo.write('extensions/probe/index.js', `try ${n}\n`);
repo.commit(`try ${n}`);
}
return repo;
};

describe('extension release --changed: an older commit', () => {
test('a re-run of an older commit is refused for an id tagged later; others still go', async () => {
const { repo, c1, records } = oldAndNew();
const run = await release({ dir: checkoutAt(repo, c1), w: { records } });
expect(run.code).toBe('release_refused');
expect(run.error).toMatch(
/^probe: FAIL history: probe@2026\.1122\.1 is on \w{40}, which is not/
);
expect(run.error).toContain(`not before ${c1}: an older commit is refused`);
expect(tagged(run.calls)).toEqual([
`gh api repos/agentage/examples/git/refs -f ref=refs/tags/fixture@2026.1122.1 -f sha=${c1}`,
]);
expect(run.lines.slice(-3)).toEqual([
'id version result',
'probe - refused',
'fixture 2026.1122.1 released',
]);
});
});

describe('extension release --changed: tags with no record', () => {
test('three in a row with no record: refused, the three named, no new tag', async () => {
const run = await release({ dir: ciClone(failedTags(3)), opts: { dryRun: true } });
expect(run.error).toBe(
'probe: FAIL stuck: probe@2026.1122.3, probe@2026.1122.2, probe@2026.1122.1 have no record: fix the release, or remove those tags'
);
expect(run.lines).toContain('probe - refused');
});

test('two with no record: still released with the next N', async () => {
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'
);
});

test('a record on the newest tag breaks the row: one record check only', async () => {
const repo = failedTags(3);
const records = { 'probe@2026.1122.3': repo.git('rev-list', '-n', '1', 'probe@2026.1122.3') };
const run = await release({ dir: ciClone(repo), w: { records }, opts: { dryRun: true } });
expect(run.error).toBeNull();
expect(run.calls.filter((c) => c.startsWith('gh release download'))).toHaveLength(1);
});
});

describe('extension release --changed: npm and the record', () => {
test('npm fails: no record goes up, so the next commit releases a new N', async () => {
const repo = makeRepo();
writeExtension(repo, 'extensions/probe', 'probe');
repo.commit('one');
const run = await release({ dir: ciClone(repo), w: { npmFails: 'E403 forbidden' } });
expect(run.error).toBe('probe: FAIL npm: E403 forbidden');
expect(run.calls).toContain('build probe@2026.1122.1');
expect(run.calls.some((c) => c.startsWith('gh release create'))).toBe(false);
repo.tag('probe@2026.1122.1');
repo.write('README.md', 'outside the folder\n');
repo.commit('readme');
const next = await release({ dir: ciClone(repo), opts: { dryRun: true } });
expect(next.lines).toContain(
'PASS changed: probe (extensions/probe) equals probe@2026.1122.1, which has no record: release probe@2026.1122.2'
);
});
});

describe('extension release --changed: one failure', () => {
test('a failed extension does not stop the next; one table, a non-zero exit', async () => {
const repo = makeRepo();
writeExtension(repo, 'extensions/fixture', 'fixture', { api: true });
writeExtension(repo, 'extensions/probe', 'probe', { api: true });
repo.commit('two');
// A half-done contracts write leaves a file behind: it must not block the next build.
const writeContracts = async (dir: string) => {
writeFileSync(join(dir, 'openapi.json'), '{}\n');
if (dir.endsWith('fixture')) throw new Error('fixture contracts broke');
return ['openapi.json'];
};
const run = await release({ dir: ciClone(repo) }, { writeContracts });
expect(run.error).toBe('fixture: FAIL contracts: fixture contracts broke');
expect(run.calls).toContain('build probe@2026.1122.1');
expect(run.lines.slice(-3)).toEqual([
'id version result',
'fixture 2026.1122.1 failed',
'probe 2026.1122.1 released',
]);
});
});
Loading