@coffre/conformance 0.1.16 → 0.1.17

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.
package/dist/main.js CHANGED
@@ -305,6 +305,23 @@ var Report = class {
305
305
  //#endregion
306
306
  //#region src/harness.ts
307
307
  const ROOT_ADMIN = "root@conformance.example";
308
+ /**
309
+ * The CLI the deployment pins, as its pipeline runs it: `pnpm exec coffre`,
310
+ * found from its folder, so only as one of its own packages. Its entry is
311
+ * run with Node, so that it needs no bin linked, as a workspace links none
312
+ * before its build.
313
+ */
314
+ function deploymentCli(dir) {
315
+ let manifest;
316
+ try {
317
+ manifest = createRequire(join(dir, "package.json")).resolve("@coffre/cli/package.json");
318
+ } catch {
319
+ throw new Failure(`${dir} has no @coffre/cli of its own: pin it among its devDependencies, as coffre init does, and install`);
320
+ }
321
+ const bin = JSON.parse(readFileSync(manifest, "utf8")).bin?.coffre;
322
+ if (bin === void 0) throw new Failure(`${manifest} names no coffre bin`);
323
+ return join(dirname(manifest), bin);
324
+ }
308
325
  async function boot(kind, at, options) {
309
326
  const { port } = options;
310
327
  const dir = resolve(at);
@@ -352,8 +369,8 @@ async function boot(kind, at, options) {
352
369
  children.push(entry);
353
370
  return entry;
354
371
  }
355
- async function run(command, args) {
356
- const entry = start(args[0] ?? command, command, args, {}, false);
372
+ async function run(command, args, env = {}) {
373
+ const entry = start(args[0] ?? command, command, args, env, false);
357
374
  if (await new Promise((done) => {
358
375
  entry.child.once("exit", done);
359
376
  entry.child.once("error", done);
@@ -405,7 +422,11 @@ async function boot(kind, at, options) {
405
422
  const vaultRuntime = withDatabase(options.vaultRuntime, name);
406
423
  await using(postgres(withDatabase(options.postgres, "postgres")), (sql) => sql.exec(`CREATE DATABASE ${name}`));
407
424
  cleanup = () => using(postgres(withDatabase(options.postgres, "postgres")), (sql) => sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`));
408
- await run(bin("coffre-server"), ["migrate", owner]);
425
+ await run(process.execPath, [
426
+ deploymentCli(dir),
427
+ "migrate",
428
+ "--yes"
429
+ ], { COFFRE_MIGRATE_DATABASE_URL: owner });
409
430
  const state = join(scratch, "state");
410
431
  start("wrangler", bin("wrangler"), [
411
432
  "dev",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/conformance",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Checks a coffre deployment from outside: what it must never do, whatever code it runs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "dependencies": {
32
32
  "jose": "6.2.3",
33
33
  "pg": "8.16.3",
34
- "@coffre/cli": "0.1.16",
35
- "@coffre/db": "0.1.16"
34
+ "@coffre/db": "0.1.17",
35
+ "@coffre/cli": "0.1.17"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "26.1.1",
@@ -40,7 +40,7 @@
40
40
  "oauth4webapi": "3.8.8",
41
41
  "tsdown": "0.23.0",
42
42
  "typescript": "5.9.3",
43
- "@coffre/client": "0.1.16"
43
+ "@coffre/client": "0.1.17"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsdown",
package/src/harness.ts CHANGED
@@ -12,9 +12,10 @@
12
12
  // one after.
13
13
  import { spawn, type ChildProcess } from 'node:child_process';
14
14
  import { randomBytes } from 'node:crypto';
15
- import { existsSync, mkdtempSync, rmSync } from 'node:fs';
15
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
16
+ import { createRequire } from 'node:module';
16
17
  import { tmpdir } from 'node:os';
17
- import { join, resolve } from 'node:path';
18
+ import { dirname, join, resolve } from 'node:path';
18
19
  import { setTimeout as sleep } from 'node:timers/promises';
19
20
 
20
21
  import { postgres, sqlite, using, type Sql } from './database.ts';
@@ -61,6 +62,24 @@ const ROOT_ADMIN = 'root@conformance.example';
61
62
 
62
63
  type Child = { name: string; child: ChildProcess; daemon: boolean; exited: boolean; output: Buffer[] };
63
64
 
65
+ /**
66
+ * The CLI the deployment pins, as its pipeline runs it: `pnpm exec coffre`,
67
+ * found from its folder, so only as one of its own packages. Its entry is
68
+ * run with Node, so that it needs no bin linked, as a workspace links none
69
+ * before its build.
70
+ */
71
+ function deploymentCli(dir: string): string {
72
+ let manifest: string;
73
+ try {
74
+ manifest = createRequire(join(dir, 'package.json')).resolve('@coffre/cli/package.json');
75
+ } catch {
76
+ throw new Failure(`${dir} has no @coffre/cli of its own: pin it among its devDependencies, as coffre init does, and install`);
77
+ }
78
+ const bin = (JSON.parse(readFileSync(manifest, 'utf8')) as { bin?: Record<string, string> }).bin?.coffre;
79
+ if (bin === undefined) throw new Failure(`${manifest} names no coffre bin`);
80
+ return join(dirname(manifest), bin);
81
+ }
82
+
64
83
  export async function boot(kind: Kind, at: string, options: HarnessOptions): Promise<Deployment> {
65
84
  const { port } = options;
66
85
  const dir = resolve(at);
@@ -109,8 +128,8 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
109
128
  return entry;
110
129
  }
111
130
 
112
- async function run(command: string, args: string[]): Promise<void> {
113
- const entry = start(args[0] ?? command, command, args, {}, false);
131
+ async function run(command: string, args: string[], env: Record<string, string> = {}): Promise<void> {
132
+ const entry = start(args[0] ?? command, command, args, env, false);
114
133
  const code = await new Promise((done) => {
115
134
  entry.child.once('exit', done);
116
135
  entry.child.once('error', done);
@@ -175,8 +194,10 @@ export async function boot(kind: Kind, at: string, options: HarnessOptions): Pro
175
194
  using(postgres(withDatabase(options.postgres!, 'postgres')), (sql) =>
176
195
  sql.exec(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`),
177
196
  );
197
+ // As the deployment's pipeline does before it deploys: its own CLI's
198
+ // `coffre migrate`, in its folder, the owner's URL in its environment.
178
199
  // A fresh log has no heartbeat: only the scheduled job can make /readyz pass.
179
- await run(bin('coffre-server'), ['migrate', owner]);
200
+ await run(process.execPath, [deploymentCli(dir), 'migrate', '--yes'], { COFFRE_MIGRATE_DATABASE_URL: owner });
180
201
  const state = join(scratch, 'state');
181
202
  start('wrangler', bin('wrangler'), [
182
203
  'dev',