37 lines
1.6 KiB
JavaScript
37 lines
1.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
|
|
import { listRecentlyModifiedPublicHtmlRelativePaths } from './mindspace-run-public-html-scope.mjs';
|
|
|
|
test('scopes fallback HTML discovery to files modified by the current run', () => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'memind-run-html-'));
|
|
const publicDir = path.join(root, 'public');
|
|
fs.mkdirSync(publicDir, { recursive: true });
|
|
const oldPage = path.join(publicDir, 'legacy-survey.html');
|
|
const recentlyTouchedHistoricalPage = path.join(publicDir, 'startup-refreshed.html');
|
|
const currentPage = path.join(publicDir, 'iceland-aurora.html');
|
|
fs.writeFileSync(oldPage, '<html>old</html>');
|
|
fs.writeFileSync(recentlyTouchedHistoricalPage, '<html>startup refresh</html>');
|
|
fs.writeFileSync(currentPage, '<html>new</html>');
|
|
const runStartedAt = Date.now();
|
|
fs.utimesSync(oldPage, new Date(runStartedAt - 5 * 60_000), new Date(runStartedAt - 5 * 60_000));
|
|
fs.utimesSync(
|
|
recentlyTouchedHistoricalPage,
|
|
new Date(runStartedAt - 30_000),
|
|
new Date(runStartedAt - 30_000),
|
|
);
|
|
fs.utimesSync(currentPage, new Date(runStartedAt + 1_000), new Date(runStartedAt + 1_000));
|
|
|
|
assert.deepEqual(
|
|
listRecentlyModifiedPublicHtmlRelativePaths(root, { sinceMs: runStartedAt }),
|
|
['public/iceland-aurora.html'],
|
|
);
|
|
});
|
|
|
|
test('returns an empty allowlist when no run start time is available', () => {
|
|
assert.deepEqual(listRecentlyModifiedPublicHtmlRelativePaths('/missing', { sinceMs: null }), []);
|
|
});
|