Repository Public MIT Selected
1/**2 * ─────────────────────────────────────────────3 * SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 * Author : Simon-Pierre Boucher6 * Contact : contact@spboucher.ai7 * File : test/unit/research-insights.test.mjs8 * Purpose : Unit tests — research file classification, LaTeX metadata parsing, dependency manifests9 * License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import { describe, it, expect } from 'vitest';14import { classifyResearchFiles, parseTexMeta, reproChecklist } from '../../src/research/profile.mjs';15import { parseDependencies } from '../../src/insights/insights.mjs';1617const f = (path, size = 10) => ({ path, size });1819describe('classifyResearchFiles', () => {20 it('ranks the main manuscript first and finds facets', () => {21 const r = classifyResearchFiles([22 f('slides/talk.pdf'), f('paper/main.pdf'), f('paper/main.tex'), f('paper/refs.bib'),23 f('figures/fig1.png'), f('figures/fig2.pdf'), f('tables/results.tex'), f('results/run1.csv'),24 f('README.md'), f('requirements.txt'), f('Dockerfile'), f('Makefile'), f('scripts/train.py'),25 f('tests/test_model.py'), f('LICENSE'), f('CITATION.cff'), f('notebooks/explore.ipynb'),26 ]);27 expect(r.primaryPdf ?? r.pdfs[0]).toMatchObject({ path: 'paper/main.pdf' });28 expect(r.counts).toMatchObject({ pdfs: 2, tex: 2, bib: 1, figures: 2, tables: 1, outputs: 1, notebooks: 1 });29 expect(r.repro.readme).toBe('README.md');30 expect(r.repro.dockerfile).toBe('Dockerfile');31 expect(r.repro.citation).toBe('CITATION.cff');32 const checklist = reproChecklist(r.repro);33 expect(checklist.find((c) => c.key === 'env').ok).toBe(true);34 expect(checklist.find((c) => c.key === 'lock').ok).toBe(false);35 expect(checklist.find((c) => c.key === 'tests').ok).toBe(true);36 });37});3839describe('parseTexMeta', () => {40 it('extracts title, authors and counts without compiling', () => {41 const m = parseTexMeta(`\\documentclass[11pt]{article}42\\title{Housing \\emph{Liquidity} Premium}43\\author{Simon-Pierre Boucher \\and Jane Doe}44\\begin{document}\\input{sections/intro}\\cite{a}\\citep{b,c}45\\begin{figure}\\end{figure}\\begin{table*}\\end{table*}\\bibliography{refs}\\end{document}`);46 expect(m.isMain).toBe(true);47 expect(m.documentclass).toBe('article');48 expect(m.title).toBe('Housing Liquidity Premium');49 expect(m.authors).toContain('Simon-Pierre Boucher');50 expect(m.inputs).toEqual(['sections/intro']);51 expect(m.figures).toBe(1);52 expect(m.tables).toBe(1);53 expect(m.citations).toBe(2);54 expect(m.bibliography).toBe('refs');55 expect(parseTexMeta('\\section{Intro}').isMain).toBe(false);56 });57});5859describe('parseDependencies', () => {60 it('reads npm, PyPI, Cargo and Go manifests', () => {61 expect(parseDependencies('package.json', '{"dependencies":{"fastify":"^5"},"devDependencies":{"vitest":"^2"}}').deps).toEqual([62 { name: 'fastify', version: '^5', kind: 'runtime' }, { name: 'vitest', version: '^2', kind: 'dev' },63 ]);64 const py = parseDependencies('requirements.txt', 'numpy>=1.26 # math\npandas[excel]==2.2\n-e .\n');65 expect(py.ecosystem).toBe('PyPI');66 expect(py.deps.map((d) => d.name)).toEqual(['numpy', 'pandas']);67 const cargo = parseDependencies('Cargo.toml', '[package]\nname="x"\n[dependencies]\nserde = "1"\ntokio = { version = "1.2", features = ["full"] }\n[dev-dependencies]\nfoo = "1"');68 expect(cargo.deps.map((d) => `${d.name}@${d.version}`)).toEqual(['serde@1', 'tokio@1.2']);69 const go = parseDependencies('go.mod', 'module x\n\nrequire (\n\tgithub.com/a/b v1.2.3\n\tgolang.org/x/net v0.1.0 // indirect\n)');70 expect(go.deps).toHaveLength(2);71 expect(go.deps[1].kind).toBe('indirect');72 expect(parseDependencies('package.json', '{not json')).toBeNull();73 expect(parseDependencies('other.txt', '')).toBeNull();74 });75});76