@aeolus-fleet/core 0.38.10 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The label every container a test run starts carries, its value the run. The
3
+ * sweeper removes a run's containers by it, and CI checks by it that a run left
4
+ * none behind.
5
+ */
6
+ export declare const TEST_RUN_LABEL = "aeolus-fleet.test-run";
7
+ /**
8
+ * Starts the sweeper of a test run: a process of its own that removes the
9
+ * run's containers with their volumes once the run's process ends, however it
10
+ * ends. A run's teardown removes them too, but an interrupted or killed run
11
+ * never reaches it, and rootless Podman often runs no Testcontainers reaper
12
+ * (#1581). The sweeper learns the run ended when the pipe from the run's
13
+ * process closes, which the operating system does for a killed process too. It
14
+ * runs in a process group of its own, so the Ctrl-C that interrupts the run
15
+ * does not stop it, and it keeps the run's process from exiting by nothing.
16
+ * The file is the sweeper: this function starts it again as a program.
17
+ */
18
+ export declare function startContainerSweeper(run: string): void;
@@ -0,0 +1,54 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { Socket } from 'node:net';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { getContainerRuntimeClient } from 'testcontainers';
5
+ /**
6
+ * The label every container a test run starts carries, its value the run. The
7
+ * sweeper removes a run's containers by it, and CI checks by it that a run left
8
+ * none behind.
9
+ */
10
+ export const TEST_RUN_LABEL = 'aeolus-fleet.test-run';
11
+ /**
12
+ * Starts the sweeper of a test run: a process of its own that removes the
13
+ * run's containers with their volumes once the run's process ends, however it
14
+ * ends. A run's teardown removes them too, but an interrupted or killed run
15
+ * never reaches it, and rootless Podman often runs no Testcontainers reaper
16
+ * (#1581). The sweeper learns the run ended when the pipe from the run's
17
+ * process closes, which the operating system does for a killed process too. It
18
+ * runs in a process group of its own, so the Ctrl-C that interrupts the run
19
+ * does not stop it, and it keeps the run's process from exiting by nothing.
20
+ * The file is the sweeper: this function starts it again as a program.
21
+ */
22
+ export function startContainerSweeper(run) {
23
+ const sweeper = spawn(process.execPath, [fileURLToPath(import.meta.url), run], {
24
+ detached: true,
25
+ stdio: ['pipe', 'ignore', 'inherit'],
26
+ });
27
+ sweeper.unref();
28
+ // The pipe is a socket: unreferenced, it keeps the run's process from exiting by nothing either.
29
+ if (sweeper.stdin instanceof Socket) {
30
+ sweeper.stdin.unref();
31
+ }
32
+ }
33
+ /** Removes every container of the run, running or not, with its anonymous volumes. */
34
+ async function sweep(run) {
35
+ const { dockerode } = (await getContainerRuntimeClient()).container;
36
+ const containers = await dockerode.listContainers({ all: true, filters: { label: [`${TEST_RUN_LABEL}=${run}`] } });
37
+ // A container the run's teardown removes meanwhile answers not found: it is gone either way.
38
+ await Promise.allSettled(containers.map((container) => dockerode.getContainer(container.Id).remove({ force: true, v: true })));
39
+ }
40
+ if (import.meta.main) {
41
+ const run = process.argv[2];
42
+ if (!run) {
43
+ console.error('Usage: node container-sweeper.ts <test run>');
44
+ process.exit(2);
45
+ }
46
+ process.stdin.on('end', () => {
47
+ sweep(run).catch((error) => {
48
+ console.error(`The sweeper of test run ${run} could not remove its containers:`, error);
49
+ process.exitCode = 1;
50
+ });
51
+ });
52
+ process.stdin.resume();
53
+ }
54
+ //# sourceMappingURL=container-sweeper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-sweeper.js","sourceRoot":"","sources":["../../src/testing/container-sweeper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,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D,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;QAC3B,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAClC,OAAO,CAAC,KAAK,CAAC,2BAA2B,GAAG,mCAAmC,EAAE,KAAK,CAAC,CAAC;YACxF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AACzB,CAAC"}
@@ -7,10 +7,11 @@ import { PostgreSqlContainer } from '@testcontainers/postgresql';
7
7
  * that waits for the disk waits behind every other test's writes, and under a
8
8
  * loaded full run Prisma Migrate's commits alone outlasted a test's time
9
9
  * (#499). Only a crash of the host loses a commit then, and no test survives
10
- * that anyway.
10
+ * that anyway. It carries the label of the test run that starts it, so the
11
+ * run's sweeper removes it.
11
12
  */
12
13
  export declare class TestPostgres extends PostgreSqlContainer {
13
- constructor(image: string);
14
+ constructor(image: string, run: string);
14
15
  /** Drops the check the module sets on start; the image defines none of its own. */
15
16
  protected beforeContainerCreated(): Promise<void>;
16
17
  }
@@ -1,5 +1,6 @@
1
1
  import { PostgreSqlContainer } from '@testcontainers/postgresql';
2
2
  import { Wait } from 'testcontainers';
3
+ import { TEST_RUN_LABEL } from './container-sweeper.js';
3
4
  /**
4
5
  * Postgres says it is ready twice: once for the server the image's entrypoint
5
6
  * starts to initialise the database, once for the server that stays.
@@ -13,11 +14,13 @@ const READY_LOG = /database system is ready to accept connections/;
13
14
  * that waits for the disk waits behind every other test's writes, and under a
14
15
  * loaded full run Prisma Migrate's commits alone outlasted a test's time
15
16
  * (#499). Only a crash of the host loses a commit then, and no test survives
16
- * that anyway.
17
+ * that anyway. It carries the label of the test run that starts it, so the
18
+ * run's sweeper removes it.
17
19
  */
18
20
  export class TestPostgres extends PostgreSqlContainer {
19
- constructor(image) {
21
+ constructor(image, run) {
20
22
  super(image);
23
+ this.withLabels({ [TEST_RUN_LABEL]: run });
21
24
  this.withCommand(['postgres', '-c', 'fsync=off']);
22
25
  this.withWaitStrategy(Wait.forAll([Wait.forLogMessage(READY_LOG, 2), Wait.forListeningPorts()]));
23
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-container.js","sourceRoot":"","sources":["../../src/testing/postgres-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC;;;GAGG;AACH,MAAM,SAAS,GAAG,gDAAgD,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,OAAO,YAAa,SAAQ,mBAAmB;IACnD,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;IACnG,CAAC;IAED,mFAAmF;IAChE,KAAK,CAAC,sBAAsB;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACnC,MAAM,KAAK,CAAC,sBAAsB,EAAE,EAAE,CAAC;IACzC,CAAC;CACF"}
1
+ {"version":3,"file":"postgres-container.js","sourceRoot":"","sources":["../../src/testing/postgres-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;GAGG;AACH,MAAM,SAAS,GAAG,gDAAgD,CAAC;AAEnE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YAAa,SAAQ,mBAAmB;IACnD,YAAY,KAAa,EAAE,GAAW;QACpC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,CAAC;IACnG,CAAC;IAED,mFAAmF;IAChE,KAAK,CAAC,sBAAsB;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACnC,MAAM,KAAK,CAAC,sBAAsB,EAAE,EAAE,CAAC;IACzC,CAAC;CACF"}
@@ -3,6 +3,8 @@ declare module 'vitest' {
3
3
  interface ProvidedContext {
4
4
  /** Admin URL of the Postgres container shared by the integration tests. */
5
5
  postgresUrl: string;
6
+ /** The test run, the label value of every container it starts, for its sweeper to remove them. */
7
+ testRun: string;
6
8
  }
7
9
  }
8
10
  /**
@@ -10,6 +12,8 @@ declare module 'vitest' {
10
12
  * own database in it (see database.ts), so files stay isolated; a
11
13
  * migrated one is a copy of the template migrated here, before any test runs.
12
14
  * Testcontainers reads the reaper image from the environment when it starts
13
- * the first container; a reaper image set from outside wins.
15
+ * the first container; a reaper image set from outside wins. The run's sweeper
16
+ * starts before any container, so a run that never reaches its teardown still
17
+ * leaves none behind.
14
18
  */
15
19
  export declare function setup(project: TestProject): Promise<() => Promise<void>>;
@@ -1,4 +1,6 @@
1
+ import { randomUUID } from 'node:crypto';
1
2
  import { POSTGRES_IMAGE, REAPER_IMAGE } from './container-images.js';
3
+ import { startContainerSweeper } from './container-sweeper.js';
2
4
  import { TestPostgres } from './postgres-container.js';
3
5
  import { createMigratedTemplate } from './migrated-template.js';
4
6
  /**
@@ -6,11 +8,16 @@ import { createMigratedTemplate } from './migrated-template.js';
6
8
  * own database in it (see database.ts), so files stay isolated; a
7
9
  * migrated one is a copy of the template migrated here, before any test runs.
8
10
  * Testcontainers reads the reaper image from the environment when it starts
9
- * the first container; a reaper image set from outside wins.
11
+ * the first container; a reaper image set from outside wins. The run's sweeper
12
+ * starts before any container, so a run that never reaches its teardown still
13
+ * leaves none behind.
10
14
  */
11
15
  export async function setup(project) {
12
16
  process.env.RYUK_CONTAINER_IMAGE ??= REAPER_IMAGE;
13
- const container = await new TestPostgres(POSTGRES_IMAGE).start();
17
+ const run = randomUUID();
18
+ startContainerSweeper(run);
19
+ project.provide('testRun', run);
20
+ const container = await new TestPostgres(POSTGRES_IMAGE, run).start();
14
21
  await createMigratedTemplate(container.getConnectionUri());
15
22
  project.provide('postgresUrl', container.getConnectionUri());
16
23
  return async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-global-setup.js","sourceRoot":"","sources":["../../src/testing/postgres-global-setup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAShE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAoB;IAC9C,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,YAAY,CAAC;IAClD,MAAM,SAAS,GAAG,MAAM,IAAI,YAAY,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,CAAC;IACjE,MAAM,sBAAsB,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAE7D,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"postgres-global-setup.js","sourceRoot":"","sources":["../../src/testing/postgres-global-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAWhE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAoB;IAC9C,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,YAAY,CAAC;IAClD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAChC,MAAM,SAAS,GAAG,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACtE,MAAM,sBAAsB,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAE7D,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeolus-fleet/core",
3
- "version": "0.38.10",
3
+ "version": "0.39.0",
4
4
  "description": "The Aeolus fleet server: ships, guaranteed delivery and the API for Claude Code, Codex and any agent.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -59,7 +59,7 @@
59
59
  "postpack": "rm LICENSE"
60
60
  },
61
61
  "dependencies": {
62
- "@aeolus-fleet/common": "0.38.10",
62
+ "@aeolus-fleet/common": "0.39.0",
63
63
  "@aws-sdk/client-kms": "^3.1159.0",
64
64
  "@fastify/websocket": "^11.3.1",
65
65
  "@modelcontextprotocol/server": "^2.3.0",
@@ -0,0 +1,11 @@
1
+ -- A crew request's workspace names a main repository and its sub-repositories
2
+ -- (#1760): a stored worktree workspace becomes repositories, that repository
3
+ -- (and its ref) as main and no sub-repositories, so no standing request holds
4
+ -- settings no trierarch can read (decision 0013).
5
+ UPDATE "crew_requests"
6
+ SET "settings" = jsonb_set(
7
+ "settings",
8
+ '{workspace}',
9
+ jsonb_build_object('kind', 'repositories', 'main', ("settings"->'workspace') - 'kind', 'subRepositories', '[]'::jsonb)
10
+ )
11
+ WHERE "settings"->'workspace'->>'kind' = 'worktree';