import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';

const root = new URL('../', import.meta.url);

test('incremental native and Wasm builds authenticate their materialized patch state', async () => {
  const scripts = await Promise.all([
    readFile(new URL('tools/build-native.sh', root), 'utf8'),
    readFile(new URL('tools/build-wasm.sh', root), 'utf8'),
  ]);

  for (const script of scripts) {
    assert.match(script, /openq4_diff_sha256=\%s/);
    assert.match(script, /gamelibs_diff_sha256=\%s/);
    assert.match(script, /openq4_materialized_diff_sha/);
    assert.match(script, /gamelibs_materialized_diff_sha/);
    assert.match(script, /diff --binary --no-ext-diff/);
    assert.match(script, /materialized patched source differs from its stamp/);
    assert.match(script, /rerun with --clean/);
  }
});
