Skip to content
Open
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
4 changes: 2 additions & 2 deletions scripts/sync-model-metadata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ async function assertGeneratedOutputs(metadataPath, pricingPath, source) {
);
}

async function loadTypeScriptModule(source) {
const javascript = stripTypeScriptTypes(source, { mode: 'transform' });
export async function loadTypeScriptModule(source) {
const javascript = stripTypeScriptTypes(source, { mode: 'strip' });
return import(`data:text/javascript;base64,${Buffer.from(javascript).toString('base64')}`);
}

Expand Down
20 changes: 19 additions & 1 deletion scripts/sync-model-metadata.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
import { main, PROVIDERS } from './sync-model-metadata.mjs';
import { loadTypeScriptModule, main, PROVIDERS } from './sync-model-metadata.mjs';

function fixtureCatalog() {
const catalog = {};
Expand All @@ -46,6 +46,24 @@ function fixtureCatalog() {
return catalog;
}

test('loads the committed generated TypeScript modules', async () => {
const [metadataSource, pricingSource] = await Promise.all([
readFile(new URL('../packages/core/src/model-metadata.generated.ts', import.meta.url), 'utf8'),
readFile(
new URL('../packages/runtime/src/telemetry/model-pricing.generated.ts', import.meta.url),
'utf8',
),
]);
const [metadataModule, pricingModule] = await Promise.all([
loadTypeScriptModule(metadataSource),
loadTypeScriptModule(pricingSource),
]);

assert.ok(Object.keys(metadataModule.GENERATED_MODELS_DEV_METADATA).length > 0);
assert.ok(Array.isArray(pricingModule.GENERATED_MODEL_PRICING));
assert.ok(pricingModule.GENERATED_MODEL_PRICING.length > 0);
});

test('a refresh persists the exact selected input and check fails on stale output', async () => {
const root = await mkdtemp(join(tmpdir(), 'maka-model-snapshot-'));
try {
Expand Down
Loading