@xlinklight/testkit 7.0.0-rc.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/LICENSE +21 -21
- package/README.md +171 -169
- package/package.json +11 -4
- package/src/architecture-database.d.mts +36 -36
- package/src/architecture-database.mjs +64 -64
- package/src/artifact-observation.mjs +50 -50
- package/src/browser-lifecycle.mjs +45 -45
- package/src/cloudflare-browser.mjs +41 -41
- package/src/cloudflare-pages.d.mts +34 -34
- package/src/cloudflare-pages.mjs +170 -170
- package/src/cloudflare-provider-http.mjs +32 -32
- package/src/cluster-directory.d.mts +16 -16
- package/src/cluster-directory.mjs +90 -90
- package/src/core-publishing.d.mts +75 -75
- package/src/core-publishing.mjs +214 -214
- package/src/dev-command-runner.mjs +97 -97
- package/src/fixture-path.mjs +19 -19
- package/src/function-admission.d.mts +1 -1
- package/src/function-admission.mjs +58 -58
- package/src/host-artifact.mjs +32 -32
- package/src/host-stop.mjs +15 -15
- package/src/lifecycle-trace.mjs +32 -32
- package/src/managed-native-fixture.d.mts +84 -84
- package/src/managed-native-fixture.mjs +209 -209
- package/src/native-fixture.mjs +125 -125
- package/src/native-platform.mjs +56 -56
- package/src/operator-accounts.mjs +103 -103
- package/src/owned-process.mjs +75 -75
- package/src/owner-build-cli.mjs +3 -4
- package/src/owner-database.mjs +215 -215
- 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 +63 -33
- package/src/owner-production-browser.mjs +215 -215
- package/src/owner-production-instances.mjs +41 -41
- package/src/owner-production.d.mts +114 -104
- package/src/owner-production.mjs +350 -338
- package/src/owner-worker-build.mjs +83 -83
- package/src/prebuilt-output.d.mts +2 -2
- package/src/prebuilt-output.mjs +104 -104
- package/src/production-hosts.mjs +38 -38
- package/src/publisher-acceptance-host-cli.mjs +12 -5
- package/src/release-build.mjs +71 -71
- package/src/release-control.mjs +45 -45
- package/src/release-coordinator.d.mts +9 -9
- package/src/release-coordinator.mjs +222 -222
- package/src/release-credentials.d.mts +8 -8
- package/src/release-credentials.mjs +97 -97
- package/src/release-mutex.mjs +38 -38
- package/src/release-operator.d.mts +6 -6
- package/src/release-operator.mjs +59 -59
- package/src/release-supabase.d.mts +7 -7
- package/src/release-supabase.mjs +37 -37
- package/src/release-vercel.d.mts +22 -22
- package/src/release-vercel.mjs +51 -51
- package/src/release-writer.d.mts +6 -6
- package/src/release-writer.mjs +172 -172
- package/src/retained-postgres-shutdown.d.mts +51 -51
- package/src/retained-postgres-shutdown.mjs +262 -262
- package/src/temporary-acquisition.mjs +62 -62
- package/src/temporary-scope.d.mts +47 -47
- package/src/temporary-scope.mjs +268 -268
- package/src/worker-artifact.mjs +214 -214
|
@@ -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,33 +1,63 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import {createHash} from 'node:crypto';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
if(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {createHash} from 'node:crypto';
|
|
4
|
+
import {readOwnerDeploymentFile} from './owner-deployment-definition.mjs';
|
|
5
|
+
|
|
6
|
+
const fail=()=>Error('OWNER_OPERATOR_BUILD_INVALID');
|
|
7
|
+
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
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";
|
|
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
|
+
}
|
|
20
|
+
/** Build the installed trusted oracle library. Public Core ports stay public
|
|
21
|
+
* imports; no provider SDK or uploaded business module is evaluated here. */
|
|
22
|
+
export async function prepareOwnerOperatorBuild({root,signal}={}){
|
|
23
|
+
if(typeof root!=='string'||!path.isAbsolute(root))throw fail();signal?.throwIfAborted();root=await fs.realpath(root);
|
|
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)}}});
|
|
46
|
+
signal?.throwIfAborted();const outputs=(Array.isArray(result)?result:[result]).flatMap(value=>value.output??[]);
|
|
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();
|
|
48
|
+
const chunk=outputs[0],allowed=new Set(['@xlinklight/testkit/owner-production','@xlinklight/testkit/acceptance-oracle','@xlinklight/platform/worker','node:assert/strict']);
|
|
49
|
+
if(chunk.imports.some(value=>!allowed.has(value)))throw fail();
|
|
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();}
|
|
51
|
+
const phaseDeclaration=chunk.exports.includes('productionPhaseNames')?"export const productionPhaseNames:ReturnType<typeof import('@xlinklight/testkit/owner-production').ownerProductionPhaseNames>;\n":'';
|
|
52
|
+
const files=[{path:'main.mjs',bytes:Buffer.from(chunk.code)},{path:'main.d.mts',bytes:Buffer.from(declaration+phaseDeclaration)}];if(files[0].bytes.byteLength>4194304)throw fail();
|
|
53
|
+
const output=path.join(root,'dist-operator');let exists=true;try{await fs.lstat(output);}catch(error){if(error.code!=='ENOENT')throw error;exists=false;}
|
|
54
|
+
if(exists){
|
|
55
|
+
if(await fs.realpath(output)!==output)throw fail();const names=(await fs.readdir(output)).sort();if(names.join(',')!=='main.d.mts,main.mjs,operator-build.json')throw fail();
|
|
56
|
+
const previous=JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(await regular(path.join(output,'operator-build.json'),65536)));
|
|
57
|
+
if(previous.schemaVersion!==1||previous.kind!=='operator'||!Array.isArray(previous.files)||previous.files.length!==2)throw fail();
|
|
58
|
+
for(const file of files){const record=previous.files.find(value=>value.path===file.path),bytes=await regular(path.join(output,file.path),4194304);if(record?.sha256!==sha(bytes)||record.bytes!==bytes.byteLength)throw fail();}
|
|
59
|
+
}else await fs.mkdir(output);
|
|
60
|
+
const record={schemaVersion:1,kind:'operator',files:files.map(file=>({path:file.path,bytes:file.bytes.byteLength,sha256:sha(file.bytes)}))};
|
|
61
|
+
for(const file of files)await fs.writeFile(path.join(output,file.path),file.bytes);
|
|
62
|
+
await fs.writeFile(path.join(output,'operator-build.json'),JSON.stringify(record)+'\n');return {status:'OWNER_OPERATOR_BUILT',...record};
|
|
63
|
+
}
|