@@ -2,16 +2,16 @@ import fs from "node:fs/promises";
22import os from "node:os" ;
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
5- import { ingest , insertChaptersFile } from "../commands/ingest.js" ;
65import { closeDb , getDb } from "../db/client.js" ;
76import { chapter , chapterRun , keyChange } from "../db/schema/index.js" ;
7+ import { importChaptersFile , insertChaptersFile } from "../runs/import-chapters.js" ;
88import { makeFixture } from "./fixtures.js" ;
99
1010let tmpDir : string ;
1111let dbPath : string ;
1212
1313beforeEach ( async ( ) => {
14- tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "stage-cli-ingest -" ) ) ;
14+ tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "stage-cli-import -" ) ) ;
1515 dbPath = path . join ( tmpDir , "db.sqlite" ) ;
1616 closeDb ( ) ;
1717} ) ;
@@ -21,14 +21,14 @@ afterEach(async () => {
2121 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
2222} ) ;
2323
24- describe ( "ingest " , ( ) => {
24+ describe ( "chapter import " , ( ) => {
2525 it ( "inserts a run, chapters, and key_changes atomically and returns the runId" , async ( ) => {
2626 const db = getDb ( { dbPath } ) ;
2727 const fixture = makeFixture ( ) ;
2828 const fixturePath = path . join ( tmpDir , "chapters.json" ) ;
2929 await fs . writeFile ( fixturePath , JSON . stringify ( fixture ) ) ;
3030
31- const result = ingest ( fixturePath , db ) ;
31+ const result = importChaptersFile ( fixturePath , db ) ;
3232
3333 expect ( result . runId ) . toMatch ( / ^ [ 0 - 9 a - f - ] { 36 } $ / ) ;
3434 expect ( result . chapterCount ) . toBe ( 1 ) ;
@@ -56,7 +56,7 @@ describe("ingest", () => {
5656 ] ) ;
5757 } ) ;
5858
59- it ( "creates a new run on re-ingest of identical content (history preserved)" , ( ) => {
59+ it ( "creates a new run when importing identical content again (history preserved)" , ( ) => {
6060 const db = getDb ( { dbPath } ) ;
6161 const fixture = makeFixture ( ) ;
6262
@@ -68,7 +68,7 @@ describe("ingest", () => {
6868 expect ( db . select ( ) . from ( chapter ) . all ( ) ) . toHaveLength ( 2 ) ;
6969 } ) ;
7070
71- it ( "derives stable externalIds for key_changes across re-ingests of the same scope" , ( ) => {
71+ it ( "derives stable externalIds for key_changes across repeated imports of the same scope" , ( ) => {
7272 const db = getDb ( { dbPath } ) ;
7373 const fixture = makeFixture ( ) ;
7474
@@ -80,7 +80,7 @@ describe("ingest", () => {
8080 expect ( all [ 0 ] ?. externalId ) . toBe ( all [ 1 ] ?. externalId ) ;
8181 } ) ;
8282
83- it ( "derives stable chapter externalIds across re-ingests of the same scope" , ( ) => {
83+ it ( "derives stable chapter externalIds across repeated imports of the same scope" , ( ) => {
8484 const db = getDb ( { dbPath } ) ;
8585 insertChaptersFile ( db , makeFixture ( ) , "/repo" ) ;
8686 insertChaptersFile ( db , makeFixture ( ) , "/repo" ) ;
@@ -165,7 +165,7 @@ describe("ingest", () => {
165165 } ) ,
166166 ) ;
167167
168- expect ( ( ) => ingest ( bad , db ) ) . toThrow ( ) ;
168+ expect ( ( ) => importChaptersFile ( bad , db ) ) . toThrow ( ) ;
169169 expect ( db . select ( ) . from ( chapterRun ) . all ( ) ) . toHaveLength ( 0 ) ;
170170 expect ( db . select ( ) . from ( chapter ) . all ( ) ) . toHaveLength ( 0 ) ;
171171 } ) ;
0 commit comments