Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

1.7 KB
Raw Blame
import test from 'node:test';import assert from 'node:assert/strict';import {readdir,readFile,access} from 'node:fs/promises';import {parse} from 'acorn';import {resolve,dirname,join} from 'node:path';import {fileURLToPath} from 'node:url';
const web=fileURLToPath(new URL('../web/',import.meta.url));
test('public scene modules have a closed local import graph without author machine paths',async()=>{const files=[];async function walk(dir){for(const entry of await readdir(dir,{withFileTypes:true})){const path=join(dir,entry.name);if(entry.isDirectory())await walk(path);else if(/\.(?:mjs|js)$/.test(path))files.push(path);}}await walk(web);assert.ok(files.length>100);for(const file of files){const text=await readFile(file,'utf8');assert.equal(/C:[\\/]|\/home\/matthewk|\.kiln\/workspace/.test(text),false,file);const tree=parse(text,{ecmaVersion:'latest',sourceType:'module'}),imports=[];function literals(node){if(node?.type==='Literal'&&typeof node.value==='string')imports.push(node.value);else if(node?.type==='ConditionalExpression'){literals(node.consequent);literals(node.alternate);}}function visit(node){if(!node||typeof node!=='object')return;if(['ImportDeclaration','ExportAllDeclaration','ExportNamedDeclaration','ImportExpression'].includes(node.type))literals(node.source);for(const value of Object.values(node)){if(Array.isArray(value))for(const child of value)visit(child);else if(value&&typeof value==='object')visit(value);}}visit(tree);for(const specifier of imports){if(specifier.startsWith('.')){const target=resolve(dirname(file),specifier);assert.ok(target.startsWith(resolve(web)),specifier);await access(target);}else assert.ok(specifier==='three'||specifier.startsWith('three/'),specifier);}}});