Download server/tools.test.js from SSSAssist/Thoth: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/SSSAssist/Thoth/resolve/main/server/tools.test.js
- Command line
-
hf download hf://spaces/SSSAssist/Thoth/server/tools.test.js
-
curl -L -o tools.test.js https://huggingface.co/spaces/SSSAssist/Thoth/resolve/main/server/tools.test.js
2.32 kB
| import assert from 'node:assert/strict'; | |
| import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'; | |
| import { tmpdir } from 'node:os'; | |
| import path from 'node:path'; | |
| import { test } from 'node:test'; | |
| import { flattenIncludes, sanitizeAst } from './tools.js'; | |
| test('flattenIncludes yalnızca proje dosyalarını birleştirir', () => { | |
| const files = new Map([ | |
| ['main.tex', 'A\n\\input{bolumler/giris}\n\\include{son.tex}\n\\input{C:/Windows/win.ini}\n\\input{../disari}\nB'], | |
| ['bolumler/giris.tex', 'GİRİŞ'], | |
| ['son.tex', 'SON'], | |
| ]); | |
| const out = flattenIncludes(files, 'main.tex'); | |
| assert.match(out, /GİRİŞ/); | |
| assert.match(out, /SON/); | |
| // Proje dışı yollar çözülmez, olduğu gibi kalır (Pandoc da sandbox içinde onları okuyamaz). | |
| assert.match(out, /\\input\{C:\/Windows\/win\.ini\}/); | |
| assert.match(out, /\\input\{\.\.\/disari\}/); | |
| }); | |
| test('flattenIncludes yorumdaki komutlara ve döngülere dokunmaz', () => { | |
| const files = new Map([ | |
| ['main.tex', '% \\input{a}\nmetin % \\input{a}\n\\input{a}'], | |
| ['a.tex', 'A \\input{main}'], | |
| ]); | |
| assert.equal(flattenIncludes(files, 'main.tex'), '% \\input{a}\nmetin % \\input{a}\n\nA \\input{main}\n'); | |
| }); | |
| test('sanitizeAst yalnızca çalışma klasöründeki resimleri ve güvenli üst bilgileri bırakır', () => { | |
| const work = mkdtempSync(path.join(tmpdir(), 'thoth-ast-')); | |
| mkdirSync(path.join(work, 'sekiller')); | |
| writeFileSync(path.join(work, 'sekiller', 'grafik.png'), 'x'); | |
| const image = (url) => ({ t: 'Image', c: [['', [], []], [{ t: 'Str', c: 'alt' }], [url, '']] }); | |
| const ast = { | |
| 'pandoc-api-version': [1, 23], | |
| meta: { title: { t: 'MetaInlines', c: [] }, bibliography: { t: 'MetaString', c: '../../baska.bib' } }, | |
| blocks: [{ t: 'Para', c: [image('sekiller/grafik'), image('C:/gizli.png'), image('../disari.png'), image('https://ornek.com/a.png'), image('sekil.pdf')] }], | |
| }; | |
| const { ast: clean, skipped } = sanitizeAst(ast, work); | |
| assert.deepEqual(Object.keys(clean.meta), ['title']); | |
| const [ok, ...rest] = clean.blocks[0].c; | |
| assert.equal(ok.t, 'Image'); | |
| assert.equal(ok.c[2][0], path.join(work, 'sekiller', 'grafik.png')); | |
| assert.ok(rest.every((n) => n.t === 'Emph')); | |
| assert.deepEqual(skipped, ['C:/gizli.png', '../disari.png', 'https://ornek.com/a.png', 'sekil.pdf']); | |
| }); | |