opral / lix-sdk

1 stars 0 forks source link

`getFirstCommitHash()` in shallow cloned repo will cause node to exit(0) #18

Closed jldec closed 4 months ago

jldec commented 4 months ago

Context

Discovered while debugging faling test in https://github.com/opral/monorepo/pull/2549
The github/actions/checkout performs a shallow clone.
The failing test runs the inlang CLI, which loads a project that needs a new project id.
This results in a call to getFirstCommitHash() on the (shallow) checked out monorepo.
causing the cli to 💥 and the test to fail.

To reproduce locally:
(it probably doesn't matter which ref is fetched - this one happens to include the debug console.logs from the PR)

mkdir monorepo-shallow
cd monorepo-shallow
git init
git remote add origin https://github.com/opral/monorepo
git config --local gc.auto 0
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +a3694c29367597ea5614b9cad74ffba3c7923f86:refs/remotes/pull/2549/merge
git checkout --progress --force refs/remotes/pull/2549/merge
doppler secrets download  --no-file --format env --config development_internal >./.env
pnpm --prefer-offline install
pnpm build
cd inlang/source-code/sdk/multi-project-test/
pnpm inlang validate --project ./project3-dir/project.inlang
echo $?

Result of running ☝️

inlang validate terminates with exit code 0.

ℹ 🔎 Validating the inlang project...                                                                                                                                                                12:55:21 PM
using experimental git features for this repo. [ 'lazyClone', 'lixCommit' ]
Using existing cloned repo
🔔 migrated project.inlang to directory
😳 maybeCreateFirstProjectId start
😳 maybeCreateFirstProjectId try readFile /Users/jldec/opral/monorepo-shallow/inlang/source-code/sdk/multi-project-test/project3-dir/project.inlang/project_id
😳 maybeCreateFirstProjectId readFile error  ENOENT [Error: ENOENT: no such file or directory, open '/Users/jldec/opral/monorepo-shallow/inlang/source-code/sdk/multi-project-test/project3-dir/project.inlang/project_id'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/jldec/opral/monorepo-shallow/inlang/source-code/sdk/multi-project-test/project3-dir/project.inlang/project_id'
}
😳 Generating new project_id
😳 generateProjectI getFirstCommitHash
~/opral/monorepo-shallow/inlang/source-code/sdk/multi-project-test$ echo $?
0

Proposal

The call should either throw an error or return undefined if it cannot find the first commit.

jldec commented 4 months ago

@janfjohannes - I validated that this issue is resolved in https://github.com/opral/monorepo/pull/2575

$ pnpm inlang validate --project ./project3-dir/project.inlang

ℹ 🔎 Validating the inlang project...                                                                                                           1:07:46 PM
using experimental git features for this repo. [ 'lazyClone', 'lixCommit' ]
Using existing cloned repo
shallow clone detected, not generating first commit hash.
✔ The project is valid!                                                                                                                         1:07:47 PM
0
jldec commented 4 months ago

Confirmed resolved - test passes in project3 without project id.