@runeditrun/rer 0.2.91 → 0.2.93
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/cli/README.md +1 -1
- package/cli/deploy-command.mjs +19 -8
- package/cli/deploy.mjs +1 -1
- package/cli/ledger-refusal.mjs +1 -1
- package/cli/portability-migrations.mjs +9 -5
- package/cli/portability-worker.mjs +4 -2
- package/foundation/runtime/contract-docs.mjs +26 -12
- package/global/CHANGELOG.md +27 -0
- package/modules/agent-door/conformance/crypto.mjs +14 -2
- package/modules/agent-door/conformance/journey.mjs +26 -2
- package/modules/agent-door/conformance/negative.mjs +4 -1
- package/modules/agent-door/conformance/policy-phases.mjs +43 -1
- package/modules/agent-door/conformance/protocol.mjs +42 -7
- package/modules/agent-door/conformance/sponsors.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +10 -0
- package/modules/deploy-kit/owner-cli.mjs +9 -1
- package/modules/erasure/README.md +4 -2
- package/modules/operator-auth/identity/oidc/README.md +2 -1
- package/modules/portability/README.md +52 -2
- package/modules/portability/backfills.mjs +96 -3
- package/modules/portability/bridge.mjs +3 -1
- package/modules/portability/format.mjs +1 -0
- package/modules/portability/import.mjs +58 -3
- package/modules/portability/index.d.mts +2 -0
- package/modules/portability/index.mjs +16 -5
- package/modules/portability/library-history.mjs +152 -0
- package/modules/portability/migration-history.mjs +3 -2
- package/modules/portability/snapshot-objects.mjs +16 -0
- package/onboarding/adapter.mjs +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { catalogue, policy } from './catalogue.mjs';
|
|
2
|
+
import { sha256 } from './hash.mjs';
|
|
3
|
+
import { destinationLedger, matchMigrationLedger } from './ledgers.mjs';
|
|
4
|
+
import { splitStatements } from './sql-text.mjs';
|
|
5
|
+
import { insist, PortabilityError } from './storage.mjs';
|
|
6
|
+
import { migrationReplay } from './migration-history.mjs';
|
|
7
|
+
|
|
8
|
+
// Node library callers have the same checkout evidence as the runner. Resolve
|
|
9
|
+
// only its single declared D1 migration directory, never an archive-supplied path.
|
|
10
|
+
// Variable imports keep Node builtins out of a Worker's module graph.
|
|
11
|
+
const nodeModule = name => import(name);
|
|
12
|
+
export async function libraryMigrations(db,config,root) {
|
|
13
|
+
try{return await checkoutMigrations(db,config,root);}
|
|
14
|
+
catch(error){if(error instanceof PortabilityError)throw error;throw new PortabilityError('schema_mismatch:legacy_evidence',409);}
|
|
15
|
+
}
|
|
16
|
+
async function checkoutMigrations(db,config,root) {
|
|
17
|
+
insist(typeof process!=='undefined' && process.versions?.node,'schema_mismatch:legacy_evidence',409);
|
|
18
|
+
const [{readFile,readdir},{resolve,sep}]=await Promise.all([nodeModule('node:fs/promises'),nodeModule('node:path')]);
|
|
19
|
+
root=resolve(root??process.cwd());
|
|
20
|
+
const declaration=parseJsonc(await readFile(resolve(root,'wrangler.jsonc'),'utf8'));
|
|
21
|
+
insist(declaration.d1_databases?.length===1,'schema_mismatch:legacy_evidence',409);
|
|
22
|
+
const directory=resolve(root,declaration.d1_databases[0].migrations_dir??'migrations');
|
|
23
|
+
insist(directory===root || directory.startsWith(root+sep),'schema_mismatch:legacy_evidence',409);
|
|
24
|
+
const files=await Promise.all((await readdir(directory)).filter(name=>name.endsWith('.sql')).sort().map(async name=>{
|
|
25
|
+
const bytes=await readFile(resolve(directory,name));
|
|
26
|
+
return {name,sha256:await sha256(bytes),statements:splitStatements(bytes.toString('utf8'))};
|
|
27
|
+
}));
|
|
28
|
+
const ledger=await destinationLedger(db)??[];
|
|
29
|
+
insist(ledger.length && ledger.every(row=>row.sha256),'schema_mismatch:legacy_evidence',409);
|
|
30
|
+
const applied=matchMigrationLedger(ledger,files);
|
|
31
|
+
const replay=migrationReplay(applied.map(name=>files.find(file=>file.name===name)),config);
|
|
32
|
+
insist(await replay.schemaAfter(replay.names)===(await catalogue(db,policy(config))).identity,'schema_mismatch');
|
|
33
|
+
return async()=>replay;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// This copied runtime cannot depend on the authoring CLI. Keep the strict
|
|
37
|
+
// JSONC reader local so checkout configuration has the same syntax rules.
|
|
38
|
+
function location(text, position) {
|
|
39
|
+
const lines = text.slice(0, position).split('\n');
|
|
40
|
+
return `position ${position} (line ${lines.length} column ${lines.at(-1).length + 1})`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Validate JSONC before JSON.parse so diagnostics do not depend on the Node
|
|
44
|
+
// version's error wording. An explicit stack also handles deeply nested input.
|
|
45
|
+
// Only comments and commas accepted by the grammar are masked; offsets stay in
|
|
46
|
+
// the original source and comment removal can never join separate tokens.
|
|
47
|
+
function parseJsonc(text, onProperty) {
|
|
48
|
+
const result = text.split(''), stack = [{ kind: 'root', state: 'value', path: [] }];
|
|
49
|
+
let index = 0;
|
|
50
|
+
const fail = (message, position = index) => {
|
|
51
|
+
throw new SyntaxError(`${position === text.length ? 'Unexpected end of JSON input' : message} at ${location(text, position)}`);
|
|
52
|
+
};
|
|
53
|
+
const unterminated = (kind, start) => {
|
|
54
|
+
throw new SyntaxError(`Unterminated ${kind} at ${location(text, start)}; close the ${kind}.`);
|
|
55
|
+
};
|
|
56
|
+
const blank = start => {
|
|
57
|
+
for (let i = start; i < index; i++) if (text[i] !== '\n' && text[i] !== '\r') result[i] = ' ';
|
|
58
|
+
};
|
|
59
|
+
const space = () => {
|
|
60
|
+
while (index < text.length) {
|
|
61
|
+
if (' \t\r\n'.includes(text[index])) { index++; continue; }
|
|
62
|
+
const start = index;
|
|
63
|
+
if (text[index] === '/' && text[index + 1] === '/') {
|
|
64
|
+
index += 2;
|
|
65
|
+
while (index < text.length && text[index] !== '\n' && text[index] !== '\r') index++;
|
|
66
|
+
} else if (text[index] === '/' && text[index + 1] === '*') {
|
|
67
|
+
const end = text.indexOf('*/', index + 2);
|
|
68
|
+
if (end === -1) unterminated('block comment', start);
|
|
69
|
+
index = end + 2;
|
|
70
|
+
} else break;
|
|
71
|
+
blank(start);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const string = () => {
|
|
75
|
+
const start = index++;
|
|
76
|
+
let end = index;
|
|
77
|
+
while (end < text.length && text[end] !== '"') end = Math.min(text.length, end + (text[end] === '\\' ? 2 : 1));
|
|
78
|
+
if (end === text.length) unterminated('string', start);
|
|
79
|
+
while (index < end) {
|
|
80
|
+
if (text.charCodeAt(index) < 32) fail('Unescaped control character in string');
|
|
81
|
+
if (text[index++] !== '\\') continue;
|
|
82
|
+
if (text[index] === 'u') {
|
|
83
|
+
index++;
|
|
84
|
+
for (let digit = 0; digit < 4; digit++, index++) {
|
|
85
|
+
if (index >= end || !/[0-9a-fA-F]/.test(text[index])) fail('Invalid Unicode escape');
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
if (!'"\\/bfnrt'.includes(text[index])) fail('Invalid string escape');
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
index++;
|
|
93
|
+
};
|
|
94
|
+
const digit = () => index < text.length && text[index] >= '0' && text[index] <= '9';
|
|
95
|
+
const digits = () => {
|
|
96
|
+
if (!digit()) fail('Expected a digit');
|
|
97
|
+
do { index++; } while (digit());
|
|
98
|
+
};
|
|
99
|
+
const number = () => {
|
|
100
|
+
if (text[index] === '-') index++;
|
|
101
|
+
if (text[index] === '0') index++;
|
|
102
|
+
else digits();
|
|
103
|
+
if (text[index] === '.') { index++; digits(); }
|
|
104
|
+
if (text[index] === 'e' || text[index] === 'E') {
|
|
105
|
+
index++;
|
|
106
|
+
if (text[index] === '+' || text[index] === '-') index++;
|
|
107
|
+
digits();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
while (stack.length) {
|
|
111
|
+
space();
|
|
112
|
+
const frame = stack.at(-1), char = text[index], closing = frame.kind === 'object' ? '}' : ']';
|
|
113
|
+
if (frame.state === 'end') {
|
|
114
|
+
if (index < text.length) fail('Unexpected token after JSON value');
|
|
115
|
+
stack.pop();
|
|
116
|
+
} else if ((frame.state === 'keyOrEnd' || frame.state === 'valueOrEnd' || frame.state === 'comma') && char === closing) {
|
|
117
|
+
index++; stack.pop();
|
|
118
|
+
} else if (frame.state === 'keyOrEnd') {
|
|
119
|
+
if (char !== '"') fail('Expected a property name');
|
|
120
|
+
const start = index; string();
|
|
121
|
+
frame.key = onProperty ? JSON.parse(text.slice(start, index)) : undefined;
|
|
122
|
+
onProperty?.([...frame.path, frame.key], start);
|
|
123
|
+
frame.state = 'colon';
|
|
124
|
+
} else if (frame.state === 'colon') {
|
|
125
|
+
if (char !== ':') fail("Expected ':' after property name");
|
|
126
|
+
index++; frame.state = 'value';
|
|
127
|
+
} else if (frame.state === 'comma') {
|
|
128
|
+
if (char !== ',') fail(`Expected ',' or '${closing}'`);
|
|
129
|
+
const comma = index++;
|
|
130
|
+
space();
|
|
131
|
+
if (text[index] === closing) result[comma] = ' ';
|
|
132
|
+
frame.state = frame.kind === 'object' ? 'keyOrEnd' : 'valueOrEnd';
|
|
133
|
+
} else {
|
|
134
|
+
const path = !onProperty ? undefined : frame.kind === 'root' ? [] : [...frame.path, frame.kind === 'array' ? frame.next++ : frame.key];
|
|
135
|
+
frame.state = frame.kind === 'root' ? 'end' : 'comma';
|
|
136
|
+
if (char === '{' || char === '[') {
|
|
137
|
+
index++;
|
|
138
|
+
stack.push({ kind: char === '{' ? 'object' : 'array', state: char === '{' ? 'keyOrEnd' : 'valueOrEnd', path, next: 0 });
|
|
139
|
+
} else if (char === '"') string();
|
|
140
|
+
else if (char === '-' || digit()) number();
|
|
141
|
+
else {
|
|
142
|
+
const literal = { t: 'true', f: 'false', n: 'null' }[char];
|
|
143
|
+
if (!literal) fail('Unexpected token in JSON value');
|
|
144
|
+
for (const expected of literal) {
|
|
145
|
+
if (text[index] !== expected) fail(`Expected '${literal}'`);
|
|
146
|
+
index++;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return JSON.parse(result.join(''));
|
|
152
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
2
1
|
import { policy, schemaIdentity } from './catalogue.mjs';
|
|
3
2
|
|
|
4
3
|
// Replays a chosen set of the destination's migrations, in its applied order,
|
|
@@ -7,8 +6,9 @@ import { policy, schemaIdentity } from './catalogue.mjs';
|
|
|
7
6
|
// destination's history (see bridge.mjs). plan: [{name,statements,sha256?}],
|
|
8
7
|
// sha256 being the migration file's hash where the runner read the file.
|
|
9
8
|
export function migrationReplay(plan,input,{dataOnly=[]}={}) {
|
|
10
|
-
const config=policy(input);
|
|
9
|
+
const config=policy(input),sqlite='node:sqlite';
|
|
11
10
|
return {names:plan.map(migration=>migration.name),dataOnly,aliases:name=>plan.find(m=>m.name===name).aliases,statements:name=>plan.find(m=>m.name===name).statements,sha256:name=>plan.find(m=>m.name===name).sha256,async schemaAfter(names,options) {
|
|
11
|
+
const {DatabaseSync}=await import(sqlite);
|
|
12
12
|
const scratch=new DatabaseSync(':memory:');
|
|
13
13
|
const db={prepare:sql=>{const query=scratch.prepare(sql);let values=[];return {bind(...args){values=args;return this;},async all(){return {results:query.all(...values)};}};}};
|
|
14
14
|
try {
|
|
@@ -19,6 +19,7 @@ export function migrationReplay(plan,input,{dataOnly=[]}={}) {
|
|
|
19
19
|
// The rows the whole replay leaves in each requested table, as sorted images (legacy-safety.mjs).
|
|
20
20
|
// A table the replay lacks, or one holding more than `limit` rows, has no entry.
|
|
21
21
|
async rowImages(requests,limit) {
|
|
22
|
+
const {DatabaseSync}=await import(sqlite);
|
|
22
23
|
const scratch=new DatabaseSync(':memory:'),found=new Map();
|
|
23
24
|
try {
|
|
24
25
|
for(const migration of plan)for(const sql of migration.statements)scratch.exec(sql);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { excludedTable } from './catalogue.mjs';
|
|
2
|
+
import { identifier } from './bookkeeping.mjs';
|
|
3
|
+
import { schemaIdentityOf } from './schema-identity.mjs';
|
|
4
|
+
|
|
5
|
+
// Project only the archive's identity. Live and replay catalogues still attest
|
|
6
|
+
// every object they contain; the original manifest remains the digest input.
|
|
7
|
+
export async function withoutAbsentExcludedObjects(manifest,cat,config) {
|
|
8
|
+
if(manifest.schemaObjects===undefined)return manifest;
|
|
9
|
+
const restorable=new Set([...manifest.tables,...cat.tables].map(table=>identifier(table.name)));
|
|
10
|
+
const present=new Set([...cat.excludedTables,...cat.tables.map(table=>table.name)].map(identifier));
|
|
11
|
+
const schemaObjects=manifest.schemaObjects.filter(object=>!(
|
|
12
|
+
manifest.excludedTables?.includes(object.table) && !restorable.has(identifier(object.table))
|
|
13
|
+
&& !present.has(identifier(object.table)) && excludedTable(object.table,config)));
|
|
14
|
+
if(schemaObjects.length===manifest.schemaObjects.length)return manifest;
|
|
15
|
+
return {...manifest,schemaObjects,schema:await schemaIdentityOf(manifest.tables,schemaObjects)};
|
|
16
|
+
}
|
package/onboarding/adapter.mjs
CHANGED
|
@@ -216,7 +216,9 @@ async function start(context, hooks) {
|
|
|
216
216
|
throw installationFailure('command_failed', { step: 'start', diagnostic: error });
|
|
217
217
|
}
|
|
218
218
|
let announcement,detectedMismatch;
|
|
219
|
-
|
|
219
|
+
// Keep context after the number: conservative redaction treats a trailing
|
|
220
|
+
// credential prefix as private even when it happens to be an ordinary port.
|
|
221
|
+
const mismatch=port=>({fatal:detectedMismatch=`the application listened on port ${port} but the CLI expected ${expectedPort} for the runtime listener`});
|
|
220
222
|
const announced=message=>{if(message?.type==='rer-listening')announcement=message;};
|
|
221
223
|
if(runtimePortHandshake)child.on('message',announced);
|
|
222
224
|
context.app = child;
|