import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';

const here = path.dirname(fileURLToPath(import.meta.url));

/** Регресс: списки сцен/материалов не должны дёргать assetFileUrl на каждый mount одного id. */
void test('useAssetUrl: module cache + invalidate при смене проекта', () => {
  const src = fs.readFileSync(path.join(here, 'useAssetImageUrl.ts'), 'utf8');
  const projectState = fs.readFileSync(path.join(here, '../editor/state/projectState.ts'), 'utf8');

  assert.ok(src.includes('urlCache'));
  assert.ok(src.includes('invalidateAssetUrlCache'));
  assert.ok(src.includes('peekAssetUrlCache'));
  assert.ok(src.includes('session.stateChanged'));
  assert.match(src, /urlCache\.set\(id,\s*r\.url\)/);
  assert.match(src, /peekAssetUrlCache\(id\)/);

  assert.ok(projectState.includes('invalidateAssetUrlCache'));
  assert.match(projectState, /openProject[\s\S]*?invalidateAssetUrlCache\(\)/);
  assert.match(projectState, /closeProject[\s\S]*?invalidateAssetUrlCache\(\)/);
});
