@xlinklight/testkit 7.0.0 → 8.0.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.
- package/README.md +2 -0
- package/package.json +10 -3
- package/src/owner-build-cli.mjs +3 -4
- package/src/owner-deployment-definition.mjs +31 -0
- package/src/owner-deployment.d.mts +32 -0
- package/src/owner-deployment.mjs +105 -0
- package/src/owner-operator-build.mjs +34 -4
- package/src/owner-production.d.mts +10 -0
- package/src/owner-production.mjs +12 -0
- package/src/publisher-acceptance-host-cli.mjs +12 -5
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ Run one project-scoped Node service behind the team's HTTPS ingress. Install the
|
|
|
8
8
|
pnpm exec link-light-acceptance-runner --config /absolute/private/acceptance.mjs
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Owner checkouts use `pnpm exec link-light-acceptance-runner --owner /absolute/owner-checkout` and the private `LINK_LIGHT_ACCEPTANCE_SETTINGS_FILE`. Define the lazy server, resource and operator bindings and business acceptance cases in `deployment/owner.mjs`. Point `linkLight.publishingProducer` there and forward its `prepare` export to `prepareOwnerDeploymentSource` from the Node-only `./owner-deployment` entry. The local Worker and operator build commands read the same module.
|
|
12
|
+
|
|
11
13
|
The private module exports a default `PublisherAcceptanceServiceOptions` from `@xlinklight/testkit/publisher-acceptance`. It supplies the external `origin`, loopback `port`, `publisherOrigin`, `projectId`, `solutionId`, `publisherKey` (the Publisher's Ed25519 verification key), `receiptKey` (the separately authorized project receipt signer), the absolute `root` and relative `stateDirectory`. Keep private keys and the two synthetic account credentials in protected configuration. The ingress forwards the exact acceptance paths to the loopback port and serves the configured HTTPS origin.
|
|
12
14
|
|
|
13
15
|
Supply `resolveArtifact` using `createInstalledOwnerAcceptance` with the version and SHA-256 of the trusted project's installed `/operator` bundle, its public `/resources` entry and registered resource definitions, the Core origin, the two explicit accounts and actor IDs, and the installed Playwright `expect` and browser host. `createOwnerAcceptanceBrowserHost` consumes the absolute, installed `@playwright/test` entry and private scratch directory. It uses the platform's already installed browser. When staging another version, complete the current job before replacing its installed operator, or supply an exact resolver for both immutable versions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xlinklight/testkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,6 +49,13 @@
|
|
|
49
49
|
"browser": null,
|
|
50
50
|
"import": "./src/publishing-source.mjs"
|
|
51
51
|
},
|
|
52
|
+
"./owner-deployment": {
|
|
53
|
+
"types": "./src/owner-deployment.d.mts",
|
|
54
|
+
"browser": null,
|
|
55
|
+
"workerd": null,
|
|
56
|
+
"worker": null,
|
|
57
|
+
"import": "./src/owner-deployment.mjs"
|
|
58
|
+
},
|
|
52
59
|
"./owner-build-cli": {
|
|
53
60
|
"types": "./src/owner-build-cli.d.mts",
|
|
54
61
|
"browser": null,
|
|
@@ -240,8 +247,8 @@
|
|
|
240
247
|
"@openge/forge-http-transport": "0.1.0",
|
|
241
248
|
"cloudflare": "7.3.0",
|
|
242
249
|
"@noble/hashes": "2.4.0",
|
|
243
|
-
"@xlinklight/
|
|
244
|
-
"@xlinklight/
|
|
250
|
+
"@xlinklight/platform": "5.0.0",
|
|
251
|
+
"@xlinklight/solution-sdk": "3.1.0"
|
|
245
252
|
},
|
|
246
253
|
"peerDependenciesMeta": {
|
|
247
254
|
"wrangler": {
|
package/src/owner-build-cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {fileURLToPath
|
|
4
|
+
import {fileURLToPath} from 'node:url';
|
|
5
5
|
|
|
6
6
|
const commands=new Set(['build-info','build-package','build-operator','build-worker','build-static-ui']);
|
|
7
7
|
/** Local owner builds only. Publication and credentials belong to the
|
|
@@ -15,9 +15,8 @@ export async function runOwnerBuildCommand({root,args}){
|
|
|
15
15
|
if(command==='build-package')return build.prepareOwnerPackageBuild({root});
|
|
16
16
|
if(command==='build-operator')return build.prepareOwnerOperatorBuild({root});
|
|
17
17
|
if(command==='build-worker'){
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const selected=await import(pathToFileURL(entry).href);if(typeof selected.buildWorker!=='function')throw Error('OWNER_WORKER_BUILD_MODULE_INVALID');return selected.buildWorker({root});
|
|
18
|
+
const {buildOwnerDeploymentWorker}=await import('./owner-deployment.mjs');
|
|
19
|
+
return buildOwnerDeploymentWorker({root});
|
|
21
20
|
}
|
|
22
21
|
return build.prepareOwnerStaticUiBuild({root});
|
|
23
22
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {pathToFileURL} from 'node:url';
|
|
4
|
+
|
|
5
|
+
export async function readOwnerDeploymentFile(root, relative, maximum, code) {
|
|
6
|
+
const file = path.join(root, relative);
|
|
7
|
+
const info = await fs.lstat(file).catch(error => {
|
|
8
|
+
if (error.code !== 'ENOENT') throw error;
|
|
9
|
+
});
|
|
10
|
+
if (!info?.isFile() || info.nlink !== 1 || info.size > maximum || await fs.realpath(file) !== file) throw Error(code);
|
|
11
|
+
const bytes = await fs.readFile(file);
|
|
12
|
+
if (bytes.byteLength > maximum) throw Error(code);
|
|
13
|
+
return bytes;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function loadOwnerDeployment(root) {
|
|
17
|
+
const fail = () => Error('OWNER_DEPLOYMENT_MODULE_INVALID');
|
|
18
|
+
if (typeof root !== 'string' || !path.isAbsolute(root)) throw fail();
|
|
19
|
+
root = await fs.realpath(root);
|
|
20
|
+
const relative = 'deployment/owner.mjs';
|
|
21
|
+
await readOwnerDeploymentFile(root, relative, 65536, 'OWNER_DEPLOYMENT_MODULE_INVALID');
|
|
22
|
+
const entry = pathToFileURL(path.join(root, relative));
|
|
23
|
+
const {source, production, prepare} = await import(entry.href);
|
|
24
|
+
if (typeof prepare !== 'function' ||
|
|
25
|
+
!/^@[a-z0-9][a-z0-9.-]{0,63}\/[a-z0-9][a-z0-9.-]{0,63}$/.test(source?.packageName ?? '') ||
|
|
26
|
+
typeof source.descriptionKey !== 'string' || !source.descriptionKey ||
|
|
27
|
+
['loadServer','resolveResources','resolveOperator'].some(name => typeof source[name] !== 'function') ||
|
|
28
|
+
!production?.execution || !production.browser || !Array.isArray(production.oracleStatements) ||
|
|
29
|
+
!['execution','providers','omit'].includes(production.phaseNames)) throw fail();
|
|
30
|
+
return {root, entry, source, production};
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {PublishingSourceProducer} from '@xlinklight/publishing/node';
|
|
2
|
+
import type {OwnerCloudflareWorkerBuildOptions, prepareOwnerCloudflareWorkerBuild} from './owner-worker-build.mjs';
|
|
3
|
+
import type {OwnerDeploymentProduction} from './owner-production.mjs';
|
|
4
|
+
import type {createOwnerAcceptanceServiceOptions} from './publisher-acceptance.mjs';
|
|
5
|
+
|
|
6
|
+
export interface OwnerDeploymentServer {
|
|
7
|
+
serverBinding: {
|
|
8
|
+
registration(): OwnerCloudflareWorkerBuildOptions['registration'];
|
|
9
|
+
uiExportNames: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OwnerDeploymentSource<Server extends OwnerDeploymentServer = OwnerDeploymentServer> {
|
|
14
|
+
packageName: string;
|
|
15
|
+
descriptionKey: string;
|
|
16
|
+
loadServer(): Promise<Server>;
|
|
17
|
+
resolveResources(): string;
|
|
18
|
+
resolveOperator(): string;
|
|
19
|
+
capabilities?(server: Server): Parameters<typeof import('@xlinklight/platform/server').prepareIndependentReleaseDeclarations>[0]['capabilities'];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function loadOwnerDeployment(root: string): Promise<{
|
|
23
|
+
root: string;
|
|
24
|
+
entry: URL;
|
|
25
|
+
source: OwnerDeploymentSource;
|
|
26
|
+
production: OwnerDeploymentProduction;
|
|
27
|
+
}>;
|
|
28
|
+
export function prepareOwnerDeploymentSource<Server extends OwnerDeploymentServer>(
|
|
29
|
+
source: OwnerDeploymentSource<Server>, moduleUrl: string | URL, input: Parameters<PublishingSourceProducer['prepare']>[0],
|
|
30
|
+
): ReturnType<PublishingSourceProducer['prepare']>;
|
|
31
|
+
export function buildOwnerDeploymentWorker(input: {root:string;signal?:AbortSignal}): ReturnType<typeof prepareOwnerCloudflareWorkerBuild>;
|
|
32
|
+
export function createOwnerDeploymentServiceOptions(root: string, settingsFile?: string): ReturnType<typeof createOwnerAcceptanceServiceOptions>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {createRequire} from 'node:module';
|
|
4
|
+
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
5
|
+
import {PublishingSourceError} from '@xlinklight/publishing/node';
|
|
6
|
+
import {loadOwnerDeployment, readOwnerDeploymentFile} from './owner-deployment-definition.mjs';
|
|
7
|
+
import {runOwnerSourcePreparation} from './publishing-source.mjs';
|
|
8
|
+
import {captureOwnerStaticUiFiles, prepareOwnerSolutionPackage} from './release-build.mjs';
|
|
9
|
+
import {prepareOwnerCloudflareWorkerBuild} from './owner-worker-build.mjs';
|
|
10
|
+
import {createOwnerAcceptanceServiceOptions} from './publisher-acceptance-owner.mjs';
|
|
11
|
+
|
|
12
|
+
export {loadOwnerDeployment};
|
|
13
|
+
|
|
14
|
+
const allowedEnvironment = new Set(['SYSTEMROOT','WINDIR','COMSPEC','PATHEXT','PATH','TEMP','TMP','TMPDIR','NPM_EXECPATH','LINK_LIGHT_PNPM_CLI']);
|
|
15
|
+
const requestIdPattern = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
|
|
16
|
+
const sourceBindingError = () => Error('OWNER_SOURCE_BINDING_INVALID');
|
|
17
|
+
|
|
18
|
+
async function readJson(root, file, maximum = 1048576) {
|
|
19
|
+
const bytes = await readOwnerDeploymentFile(root, file, maximum, 'OWNER_SOURCE_METADATA_INVALID');
|
|
20
|
+
return JSON.parse(new TextDecoder('utf-8', {fatal:true}).decode(bytes));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Run only inside the explicitly bound owner checkout. Credentials remain with the publisher. */
|
|
24
|
+
export async function prepareOwnerDeploymentSource(source, moduleUrl, {root, project, signal, requestId}) {
|
|
25
|
+
let processesClosed = true;
|
|
26
|
+
try {
|
|
27
|
+
signal?.throwIfAborted();
|
|
28
|
+
if (typeof root !== 'string' || !path.isAbsolute(root) || !requestIdPattern.test(requestId) ||
|
|
29
|
+
project?.packageName !== source.packageName) throw sourceBindingError();
|
|
30
|
+
root = await fs.realpath(root);
|
|
31
|
+
if (fileURLToPath(moduleUrl) !== path.join(root,'deployment/owner.mjs')) throw sourceBindingError();
|
|
32
|
+
await readOwnerDeploymentFile(root, 'deployment/owner.mjs', 65536, 'OWNER_SOURCE_BINDING_INVALID');
|
|
33
|
+
const [metadata,target,publisher] = await Promise.all([
|
|
34
|
+
readJson(root,'package.json',65536),
|
|
35
|
+
readJson(root,'deployment/target.json'),
|
|
36
|
+
readJson(root,'deployment/publisher.json'),
|
|
37
|
+
]);
|
|
38
|
+
const configuration = project.configuration;
|
|
39
|
+
if (metadata.name !== source.packageName || target.coreOrigin !== configuration?.coreOrigin ||
|
|
40
|
+
publisher.publisherId !== configuration?.publisher?.publisherId) throw sourceBindingError();
|
|
41
|
+
|
|
42
|
+
const environment = Object.fromEntries(Object.entries(process.env).filter(([key]) => allowedEnvironment.has(key.toUpperCase())));
|
|
43
|
+
environment.NEXT_TELEMETRY_DISABLED = '1';
|
|
44
|
+
environment.LINK_LIGHT_UI_HOST_ORIGIN = configuration.coreOrigin;
|
|
45
|
+
environment.LINK_LIGHT_UI_ORIGIN = 'https://static-build.invalid';
|
|
46
|
+
processesClosed = false;
|
|
47
|
+
await runOwnerSourcePreparation({
|
|
48
|
+
root, environment, signal, timeoutMs:300000, maxOutputBytes:65536,
|
|
49
|
+
checks:['build','test:release','test:ui'],
|
|
50
|
+
build:['operator:build','build:package','web:build','worker:package'],
|
|
51
|
+
postBuild:['test:release:web','test:release:runtime'],
|
|
52
|
+
});
|
|
53
|
+
processesClosed = true;
|
|
54
|
+
|
|
55
|
+
const owned = await source.loadServer();
|
|
56
|
+
const registration = owned.serverBinding.registration();
|
|
57
|
+
if (registration.descriptor.solutionId !== project.solutionId) throw sourceBindingError();
|
|
58
|
+
const displayCopy = await readJson(root,'content/i18n.json');
|
|
59
|
+
const display = Object.fromEntries(Object.entries(displayCopy).map(([locale, value]) =>
|
|
60
|
+
[locale, {name:value.title, description:value[source.descriptionKey]}]));
|
|
61
|
+
const capabilities = source.capabilities?.(owned) ?? {provided:[], required:[]};
|
|
62
|
+
const {prepareIndependentReleaseDeclarations} = await import('@xlinklight/platform/server');
|
|
63
|
+
const release = prepareIndependentReleaseDeclarations({registration,capabilities,display});
|
|
64
|
+
const uiFiles = await captureOwnerStaticUiFiles({root,limits:project.limits,signal});
|
|
65
|
+
const prepared = await prepareOwnerSolutionPackage({
|
|
66
|
+
root, workerOutput:'dist-worker', uiFiles,
|
|
67
|
+
declarations:{solutionId:project.solutionId,publisherId:publisher.publisherId,release},
|
|
68
|
+
pathCaseSensitivity:process.platform === 'win32' ? 'case-insensitive' : 'case-sensitive',
|
|
69
|
+
limits:project.limits, signal,
|
|
70
|
+
});
|
|
71
|
+
return {prepared,processesClosed:true};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error instanceof PublishingSourceError) throw error;
|
|
74
|
+
throw new PublishingSourceError({cause:error,processesClosed});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function buildOwnerDeploymentWorker({root,signal}) {
|
|
79
|
+
signal?.throwIfAborted();
|
|
80
|
+
const owner = await loadOwnerDeployment(root);
|
|
81
|
+
const require = createRequire(owner.entry);
|
|
82
|
+
const metadataFile = require.resolve('wrangler/package.json');
|
|
83
|
+
const tool = JSON.parse(await fs.readFile(metadataFile,'utf8'));
|
|
84
|
+
const wranglerEntry = await fs.realpath(path.resolve(path.dirname(metadataFile),tool.bin.wrangler));
|
|
85
|
+
const databasePath = 'dist/public/database.js';
|
|
86
|
+
await readOwnerDeploymentFile(owner.root,databasePath,1048576,'OWNER_WORKER_BUILD_ROOT_INVALID');
|
|
87
|
+
const {ownerDatabaseDomain:domain} = await import(pathToFileURL(path.join(owner.root,databasePath)).href);
|
|
88
|
+
const {serverBinding} = await owner.source.loadServer();
|
|
89
|
+
return prepareOwnerCloudflareWorkerBuild({
|
|
90
|
+
root:owner.root, bindingEntry:path.join(owner.root,'dist/public/host-binding.js'),
|
|
91
|
+
registration:serverBinding.registration(), uiExportNames:serverBinding.uiExportNames,
|
|
92
|
+
resourceEntry:new URL(owner.source.resolveResources()), domain, wranglerEntry, signal,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function createOwnerDeploymentServiceOptions(root, settingsFile = process.env.LINK_LIGHT_ACCEPTANCE_SETTINGS_FILE) {
|
|
97
|
+
const owner = await loadOwnerDeployment(root);
|
|
98
|
+
const require = createRequire(owner.entry);
|
|
99
|
+
const {serverBinding} = await owner.source.loadServer();
|
|
100
|
+
return createOwnerAcceptanceServiceOptions({
|
|
101
|
+
settingsFile, registration:serverBinding.registration(),
|
|
102
|
+
operatorEntry:owner.source.resolveOperator(), resourcesEntry:owner.source.resolveResources(),
|
|
103
|
+
playwrightEntry:require.resolve('@playwright/test'), expect:require('@playwright/test').expect,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -1,20 +1,50 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import {createHash} from 'node:crypto';
|
|
4
|
+
import {readOwnerDeploymentFile} from './owner-deployment-definition.mjs';
|
|
4
5
|
|
|
5
6
|
const fail=()=>Error('OWNER_OPERATOR_BUILD_INVALID');
|
|
6
7
|
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
7
8
|
const declaration="import {exerciseOwnerProduction,createOwnerProductionPlan} from '@xlinklight/testkit/owner-production';\nimport type {AcceptanceOracleStatement} from '@xlinklight/testkit/acceptance-oracle';\nexport type OwnerAcceptanceOptions=Omit<Parameters<typeof exerciseOwnerProduction>[0],'solutionId'|'execution'|'browser'|'providers'|'oracleStatements'>;\nexport const oracles:readonly AcceptanceOracleStatement[];\nexport function acceptOwnerRelease(options:OwnerAcceptanceOptions):ReturnType<typeof exerciseOwnerProduction>;\nexport function createOwnerAcceptancePlan(options:OwnerAcceptanceOptions):ReturnType<typeof createOwnerProductionPlan>;\n";
|
|
8
9
|
async function regular(file,maximum){const info=await fs.lstat(file);if(!info.isFile()||info.isSymbolicLink()||info.size>maximum||await fs.realpath(file)!==file)throw fail();return fs.readFile(file);}
|
|
10
|
+
|
|
11
|
+
function phaseMode(program){
|
|
12
|
+
const exports=program.body.filter(node=>node.type==='ExportNamedDeclaration'&&node.declaration?.kind==='const');
|
|
13
|
+
const production=exports.flatMap(node=>node.declaration.declarations).find(node=>node.id.type==='Identifier'&&node.id.name==='production');
|
|
14
|
+
if(production?.init?.type!=='ObjectExpression'||production.init.properties.some(node=>node.type!=='Property'||node.computed))throw fail();
|
|
15
|
+
const phases=production.init.properties.filter(node=>node.key.name==='phaseNames'||node.key.value==='phaseNames');
|
|
16
|
+
const modes=['execution','providers','omit'];
|
|
17
|
+
if(phases.length!==1||phases[0].value.type!=='Literal'||!modes.includes(phases[0].value.value))throw fail();
|
|
18
|
+
return phases[0].value.value;
|
|
19
|
+
}
|
|
9
20
|
/** Build the installed trusted oracle library. Public Core ports stay public
|
|
10
21
|
* imports; no provider SDK or uploaded business module is evaluated here. */
|
|
11
22
|
export async function prepareOwnerOperatorBuild({root,signal}={}){
|
|
12
23
|
if(typeof root!=='string'||!path.isAbsolute(root))throw fail();signal?.throwIfAborted();root=await fs.realpath(root);
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
24
|
+
const definition='deployment/owner.mjs';
|
|
25
|
+
const bytes=await readOwnerDeploymentFile(root,definition,65536,'OWNER_OPERATOR_BUILD_INVALID');
|
|
26
|
+
const {build,parseAst}=await import('vite');
|
|
27
|
+
const phases=phaseMode(parseAst(new TextDecoder('utf-8',{fatal:true}).decode(bytes)));
|
|
28
|
+
const entry=path.join(root,'deployment','owner-operator-entry.mjs');
|
|
29
|
+
const virtual='\0link-light-owner-operator';
|
|
30
|
+
const ownerFile=path.join(root,definition).split(path.sep).join('/');
|
|
31
|
+
const exports=['acceptOwnerRelease','createOwnerAcceptancePlan','oracles'];
|
|
32
|
+
if(phases!=='omit')exports.push('productionPhaseNames');
|
|
33
|
+
const operatorEntry={
|
|
34
|
+
name:'link-light-owner-operator',
|
|
35
|
+
resolveId(id){if(id===entry||id===entry.split(path.sep).join('/'))return virtual;},
|
|
36
|
+
load(id){
|
|
37
|
+
if(id!==virtual)return;
|
|
38
|
+
return [
|
|
39
|
+
"import {createOwnerProductionOperator} from '@xlinklight/testkit/owner-production';",
|
|
40
|
+
`import {production} from ${JSON.stringify(ownerFile)};`,
|
|
41
|
+
`export const {${exports.join(',')}}=createOwnerProductionOperator(production);`,
|
|
42
|
+
].join('\n');
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const result=await build({root,plugins:[operatorEntry],configFile:false,envDir:false,publicDir:false,logLevel:'silent',build:{write:false,emptyOutDir:false,minify:false,sourcemap:false,lib:{entry,formats:['es'],fileName:()=> 'main.mjs'},rolldownOptions:{external:id=>id!==virtual&&!id.startsWith('.')&&!path.isAbsolute(id)}}});
|
|
16
46
|
signal?.throwIfAborted();const outputs=(Array.isArray(result)?result:[result]).flatMap(value=>value.output??[]);
|
|
17
|
-
if(outputs.length!==1||outputs[0].type!=='chunk'||outputs[0].dynamicImports.length||outputs[0].fileName!=='main.mjs'
|
|
47
|
+
if(outputs.length!==1||outputs[0].type!=='chunk'||outputs[0].dynamicImports.length||outputs[0].fileName!=='main.mjs'||outputs[0].exports.toSorted().join(',')!==exports.join(','))throw fail();
|
|
18
48
|
const chunk=outputs[0],allowed=new Set(['@xlinklight/testkit/owner-production','@xlinklight/testkit/acceptance-oracle','@xlinklight/platform/worker','node:assert/strict']);
|
|
19
49
|
if(chunk.imports.some(value=>!allowed.has(value)))throw fail();
|
|
20
50
|
for(const id of chunk.moduleIds){if(id.startsWith('\0'))continue;const relative=path.relative(root,id);if(!relative||relative==='..'||relative.startsWith('..'+path.sep)||path.isAbsolute(relative)||relative.split(path.sep).includes('node_modules'))throw fail();}
|
|
@@ -102,3 +102,13 @@ export interface OwnerProductionPhase {
|
|
|
102
102
|
* or live handles; checkpoint must durably commit before acknowledging. */
|
|
103
103
|
export function createOwnerProductionPlan(options:OwnerProductionOptions):readonly OwnerProductionPhase[];
|
|
104
104
|
export function ownerProductionPhaseNames(providers?:readonly OwnerProductionProvider[],verifySeparately?:boolean):readonly OwnerProductionPhaseName[];
|
|
105
|
+
export interface OwnerDeploymentProduction extends Pick<OwnerProductionOptions,'execution'|'browser'|'providers'|'oracleStatements'> {
|
|
106
|
+
phaseNames:'execution'|'providers'|'omit';
|
|
107
|
+
}
|
|
108
|
+
export type OwnerAcceptanceOptions = Omit<OwnerProductionOptions,'solutionId'|'execution'|'browser'|'providers'|'oracleStatements'>;
|
|
109
|
+
export function createOwnerProductionOperator(production:OwnerDeploymentProduction):{
|
|
110
|
+
oracles:OwnerProductionOptions['oracleStatements'];
|
|
111
|
+
acceptOwnerRelease(options:OwnerAcceptanceOptions):Promise<OwnerProductionProof>;
|
|
112
|
+
createOwnerAcceptancePlan(options:OwnerAcceptanceOptions):readonly OwnerProductionPhase[];
|
|
113
|
+
productionPhaseNames:readonly OwnerProductionPhaseName[]|undefined;
|
|
114
|
+
};
|
package/src/owner-production.mjs
CHANGED
|
@@ -19,6 +19,18 @@ function productionSteps(providers,verifySeparately){
|
|
|
19
19
|
]),...['authorization','browser','cleanup'].map(name=>({name}))];
|
|
20
20
|
}
|
|
21
21
|
export function ownerProductionPhaseNames(providers=[],verifySeparately=false){return Object.freeze(productionSteps(providers,verifySeparately).map(step=>step.name));}
|
|
22
|
+
|
|
23
|
+
/** Keep source preparation and Worker bindings outside the trusted operator. */
|
|
24
|
+
export function createOwnerProductionOperator({execution,browser,providers,oracleStatements,phaseNames}){
|
|
25
|
+
const selected=({target,manifest,operator,readResourceJson,browserHost,expect,writeEvidence,signal})=>
|
|
26
|
+
({target,solutionId:manifest.solutionId,manifest,execution,browser,providers,oracleStatements,operator,readResourceJson,browserHost,expect,writeEvidence,signal});
|
|
27
|
+
return {
|
|
28
|
+
oracles:oracleStatements,
|
|
29
|
+
acceptOwnerRelease:options=>exerciseOwnerProduction(selected(options)),
|
|
30
|
+
createOwnerAcceptancePlan:options=>createOwnerProductionPlan(selected(options)),
|
|
31
|
+
productionPhaseNames:phaseNames==='omit'?undefined:ownerProductionPhaseNames(providers,phaseNames==='execution'&&execution.verifySeparately),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
22
34
|
const delay=(milliseconds,signal)=>new Promise((resolve,reject)=>{signal?.throwIfAborted();const abort=()=>{clearTimeout(timer);reject(signal.reason);},timer=setTimeout(()=>{signal?.removeEventListener('abort',abort);resolve();},milliseconds);signal?.addEventListener('abort',abort,{once:true});});
|
|
23
35
|
const append=(failed,failure,error,message)=>failed?new AggregateError([failure,error],message,{cause:failure}):error;
|
|
24
36
|
function bindPersonalRecovery(state,value,stepCount){
|
|
@@ -5,11 +5,18 @@ import {pathToFileURL} from 'node:url';
|
|
|
5
5
|
import {startPublisherAcceptanceService} from './publisher-acceptance-service.mjs';
|
|
6
6
|
|
|
7
7
|
try{
|
|
8
|
-
const [flag,
|
|
9
|
-
if(
|
|
10
|
-
|
|
11
|
-
if(
|
|
12
|
-
|
|
8
|
+
const [flag,location,...extra]=process.argv.slice(2);
|
|
9
|
+
if(!['--config','--owner'].includes(flag)||!path.isAbsolute(location??'')||extra.length)throw Error('ACCEPTANCE_RUNNER_CONFIG_REQUIRED');
|
|
10
|
+
let options;
|
|
11
|
+
if(flag==='--owner'){
|
|
12
|
+
const {createOwnerDeploymentServiceOptions}=await import('./owner-deployment.mjs');
|
|
13
|
+
options=await createOwnerDeploymentServiceOptions(location);
|
|
14
|
+
}else{
|
|
15
|
+
if(path.extname(location)!=='.mjs')throw Error('ACCEPTANCE_RUNNER_CONFIG_REQUIRED');
|
|
16
|
+
const info=await fs.lstat(location);
|
|
17
|
+
if(!info.isFile()||info.isSymbolicLink()||await fs.realpath(location)!==location)throw Error('ACCEPTANCE_RUNNER_CONFIG_UNSAFE');
|
|
18
|
+
({default:options}=await import(pathToFileURL(location).href));
|
|
19
|
+
}
|
|
13
20
|
const service=await startPublisherAcceptanceService(options);
|
|
14
21
|
let closing;
|
|
15
22
|
const close=()=>closing??=service.close().catch(()=>{process.stderr.write('ACCEPTANCE_RUNNER_CLOSE_UNKNOWN\n');process.exitCode=1;});
|