Skip to content

Commit 5119659

Browse files
test: isolate packaged handler probe results
Keep CloudWatch EMF records separate from the smoke harness's own JSON protocol. Refs #208
1 parent 20e1b6e commit 5119659

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

backend/scripts/frontend-artifact.test.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ function fixture(name) {
111111
return { root, source, artifact };
112112
}
113113

114+
function parseProbeResult(stdout) {
115+
const match = stdout.match(/^__DATAOPS_PACKAGED_HANDLER_PROBE__(.*)$/m);
116+
assert.ok(match, 'Packaged handler probe omitted its marked result record');
117+
return JSON.parse(match[1]);
118+
}
119+
114120
function run(source, artifact, extra = []) {
115121
return spawnSync(process.execPath, [verifier, '--source', source, '--artifact', artifact, ...extra], { encoding: 'utf8' });
116122
}
@@ -330,7 +336,7 @@ describe('isolated SAM handler frontend runtime', () => {
330336
const manifestAssets = readFrontendAssetManifest().files.map((asset) => `/${asset}`);
331337
const positive = await probe(isolated, ['/', '/workspace/deep-link', ...manifestAssets, '/src/../package.json', '/src/missing.js', '/public/app.js', '/public/extensionless', '/unknown.js', '/api/not-a-route', '/work/api'], 'Packaged frontend positive-route probe');
332338
assert.equal(positive.status, 0, positive.stderr);
333-
const result = JSON.parse(positive.stdout);
339+
const result = parseProbeResult(positive.stdout);
334340
assert.equal(result.outsideModuleResolution, false, JSON.stringify(result.outsideModuleResolutions));
335341
const responses = new Map(result.responses.map((response) => [response.path, response]));
336342
const responseFor = (path) => {
@@ -375,7 +381,7 @@ describe('isolated SAM handler frontend runtime', () => {
375381
renameSync(join(missing, 'dist/frontend/index.html'), join(missing, 'dist/frontend/index.missing'));
376382
const missingResult = await probe(missing, ['/'], 'Packaged frontend missing-index probe');
377383
assert.equal(missingResult.status, 0, missingResult.stderr);
378-
const missingResponse = JSON.parse(missingResult.stdout).responses[0];
384+
const missingResponse = parseProbeResult(missingResult.stdout).responses[0];
379385
assert.ok(missingResponse, '/ (missing index fixture): packaged handler returned no response');
380386
assert.equal(missingResponse.statusCode, 500, '/ (missing index fixture): missing frontend must return 500');
381387
assert.match(missingResponse.contentType, /application\/json/, '/ (missing index fixture): error must be JSON');

backend/scripts/packaged-handler-probe.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ for (const path of paths) {
6767
isBase64Encoded: Boolean(response.isBase64Encoded),
6868
});
6969
}
70-
process.stdout.write(JSON.stringify({ outsideModuleResolution, outsideModuleResolutions, responses }), () => process.exit(0));
70+
const PROBE_RESULT_PREFIX = '__DATAOPS_PACKAGED_HANDLER_PROBE__';
71+
process.stdout.write(
72+
`\n${PROBE_RESULT_PREFIX}${JSON.stringify({ outsideModuleResolution, outsideModuleResolutions, responses })}\n`,
73+
() => process.exit(0),
74+
);

0 commit comments

Comments
 (0)