Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/blocks-engine/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local state.
Threshold **0**: any drop below baseline trips a non-zero exit. This is the gate.
- **Tier B — hook path.** Scored only via cached propose/realize artifacts
(`hook-captures/`), replayed deterministically. v1 ships a deterministic stub
hook to prove the seam; a real DLA-hook capture is a fast follow. No live model
hook to prove the seam; a real reference-hook capture is a fast follow. No live model
in CI, ever.

## Expected trees (hybrid)
Expand Down
17 changes: 10 additions & 7 deletions packages/blocks-engine/scripts/capture-fixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const DLA_ROOT = process.env.DLA_ROOT ?? '/Users/matt/projects/a8c/data-liberation-agent';
const BLOCK_FIXER_DIR = path.join(DLA_ROOT, 'scripts/block-fixer');
const REFERENCE_ROOT = process.env.REFERENCE_ROOT;
if (!REFERENCE_ROOT) {
throw new Error('Set REFERENCE_ROOT to a checkout of the reference implementation.');
}
const BLOCK_FIXER_DIR = path.join(REFERENCE_ROOT, 'scripts/block-fixer');
const THIS_DIR = path.dirname(fileURLToPath(import.meta.url));
const CASES_PATH = path.resolve(THIS_DIR, '../src/__fixtures__/cases.json');

Expand Down Expand Up @@ -199,7 +202,7 @@ function withQuietConsole(fn) {
}
}

async function loadDlaFunctions() {
async function loadReferenceFunctions() {
setupWordPressGlobals();
const requireFromHere = createRequire(import.meta.url);
const { convertHtmlToBlocks, fixBlocksInTemplate } = withQuietConsole(() => ({
Expand All @@ -208,15 +211,15 @@ async function loadDlaFunctions() {
}));
try {
const { applyBlockRecipe } = await import(
pathToFileURL(path.join(DLA_ROOT, 'src/lib/replicate/apply-block-recipe.ts')).href
pathToFileURL(path.join(REFERENCE_ROOT, 'src/lib/replicate/apply-block-recipe.ts')).href
);
const { buildHtmlFallbackBlock } = await import(
pathToFileURL(path.join(DLA_ROOT, 'src/lib/replicate/html-fallback.ts')).href
pathToFileURL(path.join(REFERENCE_ROOT, 'src/lib/replicate/html-fallback.ts')).href
);
return { convertHtmlToBlocks, fixBlocksInTemplate, applyBlockRecipe, buildHtmlFallbackBlock };
} catch (error) {
throw new Error(
`Unable to import DLA TypeScript modules. Run with DLA tsx, for example: cd ${DLA_ROOT} && ./node_modules/.bin/tsx ${fileURLToPath(import.meta.url)} --check\n${error.message}`,
`Unable to import reference TypeScript modules. Run with the reference checkout's tsx, for example: cd ${REFERENCE_ROOT} && ./node_modules/.bin/tsx ${fileURLToPath(import.meta.url)} --check\n${error.message}`,
);
}
}
Expand Down Expand Up @@ -251,7 +254,7 @@ function composeWithFallback(input, applyBlockRecipe, buildHtmlFallbackBlock) {
}

async function captureCases() {
const { convertHtmlToBlocks, fixBlocksInTemplate, applyBlockRecipe, buildHtmlFallbackBlock } = await loadDlaFunctions();
const { convertHtmlToBlocks, fixBlocksInTemplate, applyBlockRecipe, buildHtmlFallbackBlock } = await loadReferenceFunctions();
const cases = [];

for (const { id, input } of RAW_CASES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const DLA_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';
const DEFAULT_DLA_ROOT = '/Users/matt/projects/a8c/data-liberation-agent';
const REFERENCE_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.resolve(__dirname, '..');
const fixtureUrl = pathToFileURL(path.join(packageRoot, 'src/__fixtures__/native-dispatch-renderer-cases.ts')).href;
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-dispatch-renderer-dla-goldens.json');
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-dispatch-renderer-reference-goldens.json');
const TSX_BOOTSTRAP_ENV = 'BLOCKS_ENGINE_NATIVE_DISPATCH_GOLDENS_TSX';

function hasTsxLoader() {
Expand All @@ -34,10 +33,13 @@ const args = new Set(process.argv.slice(2));
const shouldWrite = args.has('--write');
const shouldCheck = args.has('--check');
const shouldStdout = args.has('--stdout') || (!shouldWrite && !shouldCheck);
const dlaRoot = process.env.DLA_ROOT || DEFAULT_DLA_ROOT;
const referenceRoot = process.env.REFERENCE_ROOT;
if (!referenceRoot) {
throw new Error('Set REFERENCE_ROOT to a checkout of the reference implementation at the pinned commit.');
}

function git(args) {
return execFileSync('git', ['-C', dlaRoot, ...args], { encoding: 'utf8' }).trim();
return execFileSync('git', ['-C', referenceRoot, ...args], { encoding: 'utf8' }).trim();
}

function stableJson(value) {
Expand Down Expand Up @@ -171,23 +173,23 @@ function sandwichedRenderOut(section, result) {

function extractCardGroup(markup) {
const match = /<!-- wp:group \{"className":"is-replica-card"[\s\S]*?<!-- \/wp:group -->/.exec(markup);
if (!match) throw new Error('Could not extract is-replica-card group from DLA output');
if (!match) throw new Error('Could not extract is-replica-card group from the reference implementation output');
return match[0];
}

const currentCommit = git(['rev-parse', 'HEAD']);
if (currentCommit !== DLA_COMMIT) {
throw new Error(`DLA checkout must be at ${DLA_COMMIT}; got ${currentCommit}`);
if (currentCommit !== REFERENCE_COMMIT) {
throw new Error(`reference checkout must be at ${REFERENCE_COMMIT}; got ${currentCommit}`);
}

const dirty = git(['status', '--porcelain']);
if (dirty) {
throw new Error(`DLA checkout must be clean at ${DLA_COMMIT}; status:\n${dirty}`);
throw new Error(`reference checkout must be clean at ${REFERENCE_COMMIT}; status:\n${dirty}`);
}

const { nativeDispatchRendererCaseGroups, NATIVE_DISPATCH_RENDERER_DERIVATION } = await import(fixtureUrl);
const { reconstructPagePattern } = await import(
pathToFileURL(path.join(dlaRoot, 'src/lib/replicate/page-reconstruct.ts')).href
pathToFileURL(path.join(referenceRoot, 'src/lib/replicate/page-reconstruct.ts')).href
);

const cases = nativeDispatchRendererCaseGroups();
Expand All @@ -203,7 +205,7 @@ const renderSectionCase = (entry) => {
return capture(entry.id, renderOutFromResult(reconstructPagePattern([section], reconstructOptions())));
};
const renderCardGroupCase = (entry) => {
const result = reconstructPagePattern([clone(entry.dlaSection)], reconstructOptions());
const result = reconstructPagePattern([clone(entry.referenceSection)], reconstructOptions());
return capture(entry.id, {
returnValue: extractCardGroup(stripFinalBodyNewline(result.body)),
});
Expand All @@ -226,7 +228,7 @@ const json = stableJson(parityFile);
if (shouldCheck) {
const existing = readFileSync(outputPath, 'utf8');
if (existing !== json) {
throw new Error(`${outputPath} is out of date with DLA ${DLA_COMMIT}`);
throw new Error(`${outputPath} is out of date with reference ${REFERENCE_COMMIT}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const DLA_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';
const DEFAULT_DLA_ROOT = '/Users/matt/projects/a8c/data-liberation-agent';
const REFERENCE_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.resolve(__dirname, '..');
const fixtureUrl = pathToFileURL(path.join(packageRoot, 'src/__fixtures__/native-section-renderer-cases.ts')).href;
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-section-renderer-dla-goldens.json');
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-section-renderer-reference-goldens.json');
const TSX_BOOTSTRAP_ENV = 'BLOCKS_ENGINE_NATIVE_SECTION_GOLDENS_TSX';

function hasTsxLoader() {
Expand All @@ -34,10 +33,13 @@ const args = new Set(process.argv.slice(2));
const shouldWrite = args.has('--write');
const shouldCheck = args.has('--check');
const shouldStdout = args.has('--stdout') || (!shouldWrite && !shouldCheck);
const dlaRoot = process.env.DLA_ROOT || DEFAULT_DLA_ROOT;
const referenceRoot = process.env.REFERENCE_ROOT;
if (!referenceRoot) {
throw new Error('Set REFERENCE_ROOT to a checkout of the reference implementation at the pinned commit.');
}

function git(args) {
return execFileSync('git', ['-C', dlaRoot, ...args], { encoding: 'utf8' }).trim();
return execFileSync('git', ['-C', referenceRoot, ...args], { encoding: 'utf8' }).trim();
}

function stableJson(value) {
Expand Down Expand Up @@ -98,18 +100,18 @@ function renderOutFromResult(result) {
}

const currentCommit = git(['rev-parse', 'HEAD']);
if (currentCommit !== DLA_COMMIT) {
throw new Error(`DLA checkout must be at ${DLA_COMMIT}; got ${currentCommit}`);
if (currentCommit !== REFERENCE_COMMIT) {
throw new Error(`reference checkout must be at ${REFERENCE_COMMIT}; got ${currentCommit}`);
}

const dirty = git(['status', '--porcelain']);
if (dirty) {
throw new Error(`DLA checkout must be clean at ${DLA_COMMIT}; status:\n${dirty}`);
throw new Error(`reference checkout must be clean at ${REFERENCE_COMMIT}; status:\n${dirty}`);
}

const { nativeSectionRendererCaseGroups, NATIVE_SECTION_RENDERER_DERIVATION } = await import(fixtureUrl);
const { reconstructPagePattern } = await import(
pathToFileURL(path.join(dlaRoot, 'src/lib/replicate/page-reconstruct.ts')).href
pathToFileURL(path.join(referenceRoot, 'src/lib/replicate/page-reconstruct.ts')).href
);

const cases = nativeSectionRendererCaseGroups();
Expand All @@ -130,7 +132,7 @@ const json = stableJson(parityFile);
if (shouldCheck) {
const existing = readFileSync(outputPath, 'utf8');
if (existing !== json) {
throw new Error(`${outputPath} is out of date with DLA ${DLA_COMMIT}`);
throw new Error(`${outputPath} is out of date with reference ${REFERENCE_COMMIT}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ import { readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const DLA_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';
const DEFAULT_DLA_ROOT = '/Users/matt/projects/a8c/data-liberation-agent';
const REFERENCE_COMMIT = '1e393c535850ee1a9482f83459f779d0e225b027';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageRoot = path.resolve(__dirname, '..');
const fixtureUrl = pathToFileURL(path.join(packageRoot, 'src/__fixtures__/native-text-renderer-cases.ts')).href;
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-text-renderer-dla-goldens.json');
const outputPath = path.join(packageRoot, 'src/__fixtures__/native-text-renderer-reference-goldens.json');

const args = new Set(process.argv.slice(2));
const shouldWrite = args.has('--write');
const shouldCheck = args.has('--check');
const shouldStdout = args.has('--stdout') || (!shouldWrite && !shouldCheck);
const dlaRoot = process.env.DLA_ROOT || DEFAULT_DLA_ROOT;
const referenceRoot = process.env.REFERENCE_ROOT;
if (!referenceRoot) {
throw new Error('Set REFERENCE_ROOT to a checkout of the reference implementation at the pinned commit.');
}

function git(args) {
return execFileSync('git', ['-C', dlaRoot, ...args], { encoding: 'utf8' }).trim();
return execFileSync('git', ['-C', referenceRoot, ...args], { encoding: 'utf8' }).trim();
}

function stableJson(value) {
Expand All @@ -32,7 +34,7 @@ function stripFinalBodyNewline(markup) {

function extractGallery(markup) {
const match = markup.match(/<!-- wp:gallery\b[\s\S]*?<!-- \/wp:gallery -->/);
if (!match) throw new Error('DLA reconstruct output did not contain a wp:gallery block');
if (!match) throw new Error('reference reconstruct output did not contain a wp:gallery block');
return match[0];
}

Expand Down Expand Up @@ -85,13 +87,13 @@ function renderOutFromResult(result) {
}

const currentCommit = git(['rev-parse', 'HEAD']);
if (currentCommit !== DLA_COMMIT) {
throw new Error(`DLA checkout must be at ${DLA_COMMIT}; got ${currentCommit}`);
if (currentCommit !== REFERENCE_COMMIT) {
throw new Error(`reference checkout must be at ${REFERENCE_COMMIT}; got ${currentCommit}`);
}

const { nativeTextRendererCaseGroups, NATIVE_TEXT_RENDERER_DERIVATION } = await import(fixtureUrl);
const { reconstructPagePattern } = await import(
pathToFileURL(path.join(dlaRoot, 'src/lib/replicate/page-reconstruct.ts')).href
pathToFileURL(path.join(referenceRoot, 'src/lib/replicate/page-reconstruct.ts')).href
);

const cases = nativeTextRendererCaseGroups();
Expand Down Expand Up @@ -147,7 +149,7 @@ const json = stableJson(parityFile);
if (shouldCheck) {
const existing = readFileSync(outputPath, 'utf8');
if (existing !== json) {
throw new Error(`${outputPath} is out of date with DLA ${DLA_COMMIT}`);
throw new Error(`${outputPath} is out of date with reference ${REFERENCE_COMMIT}`);
}
}

Expand Down
Loading
Loading