11import assert from 'node:assert/strict' ;
22import fs from 'node:fs' ;
33import path from 'node:path' ;
4- import { test } from 'vitest ' ;
5- import { mkdtempForTestSync } from '../__tests__/test-utils/tmp-dir.ts' ;
4+ import { test } from 'node:test ' ;
5+ import { mkdtempForTestSync } from '../../src/ __tests__/test-utils/tmp-dir.ts' ;
66import { checkLockfileInstallSync } from './lockfile-install-sync.ts' ;
77
88function writeLockfile ( root : string , content : string ) : void {
@@ -47,9 +47,6 @@ test('reports install-missing when a source checkout has no installed snapshot',
4747test ( 'reports install-missing for a fresh worktree that has no node_modules directory at all' , ( ) => {
4848 const root = mkdtempForTestSync ( 'agent-device-lockfile-sync-fresh-worktree-' ) ;
4949 writeLockfile ( root , 'lockfileVersion: 9.0\n' ) ;
50- // Deliberately no node_modules directory — the exact state of a brand new
51- // `git worktree add`, before its first `pnpm install`. This must stay a real
52- // finding: it is the resolve-to-main-checkout trap #1963 names.
5350 assert . equal ( fs . existsSync ( path . join ( root , 'node_modules' ) ) , false ) ;
5451
5552 assert . deepEqual ( checkLockfileInstallSync ( root ) , {
@@ -58,30 +55,21 @@ test('reports install-missing for a fresh worktree that has no node_modules dire
5855 } ) ;
5956} ) ;
6057
61- test ( 'reports no-source-checkout when there is no pnpm-lock.yaml — the packaged-install shape' , ( ) => {
62- // A published agent-device: package.json `files` ships bin/ and dist/ but never the
63- // lockfile, and an npm tarball never carries node_modules. Neither file is present,
64- // and the answer must be "not applicable" rather than any kind of defect.
58+ test ( 'reports no-source-checkout when there is no pnpm-lock.yaml' , ( ) => {
6559 const root = mkdtempForTestSync ( 'agent-device-lockfile-sync-packaged-' ) ;
66- fs . mkdirSync ( path . join ( root , 'dist' ) , { recursive : true } ) ;
6760 fs . writeFileSync ( path . join ( root , 'package.json' ) , '{"name":"agent-device"}\n' ) ;
6861
6962 assert . deepEqual ( checkLockfileInstallSync ( root ) , { status : 'no-source-checkout' } ) ;
7063} ) ;
7164
72- test ( 'reports no-source-checkout even when a node_modules snapshot exists without a lockfile' , ( ) => {
73- // The lockfile is the discriminator, not the snapshot: a consuming project could have
74- // its own node_modules around the packaged install without that making our root a
75- // source checkout to diagnose.
65+ test ( 'reports no-source-checkout even when an installed snapshot exists without a lockfile' , ( ) => {
7666 const root = mkdtempForTestSync ( 'agent-device-lockfile-sync-no-lockfile-' ) ;
7767 writeInstalledSnapshot ( root , 'lockfileVersion: 9.0\n' ) ;
7868
7969 assert . deepEqual ( checkLockfileInstallSync ( root ) , { status : 'no-source-checkout' } ) ;
8070} ) ;
8171
82- test ( 'is not fooled by two worktrees sharing the same repo but different lockfile states' , ( ) => {
83- // The failure mode from #1963: a worktree's own node_modules must be compared against
84- // that same worktree's own pnpm-lock.yaml, never another checkout's.
72+ test ( 'checks each worktree against its own lockfile state' , ( ) => {
8573 const worktreeA = mkdtempForTestSync ( 'agent-device-lockfile-sync-worktree-a-' ) ;
8674 const worktreeB = mkdtempForTestSync ( 'agent-device-lockfile-sync-worktree-b-' ) ;
8775 writeLockfile ( worktreeA , 'lockfileVersion: 9.0\nimporters:\n .: {}\n' ) ;
0 commit comments