Skip to content

fix: resilient protoc resolution + add CI workflow#33

Merged
electron-rare merged 6 commits into
masterfrom
chore/protoc-resolution-and-ci
May 18, 2026
Merged

fix: resilient protoc resolution + add CI workflow#33
electron-rare merged 6 commits into
masterfrom
chore/protoc-resolution-and-ci

Conversation

@electron-rare
Copy link
Copy Markdown

Problèmes

1 — npm run protos cassé

scripts/build-proto.mjs figeait le chemin de protoc sur le binaire bundlé node_modules/grpc-tools/bin/protoc. Ce binaire est téléchargé en postinstall par grpc-tools ; quand le téléchargement échoue, le binaire est absent et npm run protos sort en status: 127. Aucun fichier proto TS n'est généré, ce qui provoquait ~431 erreurs tsc Cannot find module '@shared/proto/...' / @generated/....

2 — pas de CI sur push/PR

.github/workflows/ ne contenait que pack-cli.yml, déclenché sur les tags v*-cli. Aucun workflow ne vérifiait typecheck/lint/tests sur les push et pull requests.

Corrections

build-proto.mjs — résolution protoc avec fallback

Remplacement de la constante rigide par resolveProtoc() :

  1. binaire bundlé grpc-tools/bin/protoc(.exe) s'il existe et est exécutable (priorité, cohérence de version) ;
  2. sinon protoc trouvé sur le PATH (which/where) ;
  3. sinon un protoc qui répond à --version ;
  4. sinon message d'erreur clair (installer protoc ou réinstaller grpc-tools) + exit.

Aucune autre étape du pipeline proto n'est modifiée. Vérifié : npm run protos réussit avec le protoc système, et les erreurs tsc passent de 431 à 0.

.github/workflows/ci.yml

Nouveau workflow déclenché sur push (master) et pull_request :

  • job build (bloquant) : npm installnpm run protosnpm run check-typesnpm run lint ;
  • job test : suite unitaire mocha (test:unit) en continue-on-error car fragile en CI — elle remonte un signal sans bloquer le typecheck/lint.

Runner ubuntu-latest, Node 20, actions/setup-node@v4 avec cache: npm, cohérent avec pack-cli.yml.

Context: build-proto.mjs hard-coded the grpc-tools bundled protoc
path. When the grpc-tools postinstall download fails, that binary
is absent and `npm run protos` exits with status 127, leaving the
proto TS modules ungenerated and ~431 tsc errors.

Approach: replace the rigid constant with resolveProtoc(), a
fallback chain.

Changes:
- Try the bundled grpc-tools/bin/protoc(.exe) first, gated on an
  executable-access check, to keep version consistency.
- Fall back to a protoc found on PATH via which/where.
- Fall back to a bare protoc if it answers --version.
- Otherwise print a clear remediation message and exit.

Impact: npm run protos now succeeds with a system protoc;
no other proto pipeline behaviour changes.
Context: .github/workflows only had pack-cli.yml, triggered on
v*-cli tags. No workflow validated push or pull requests.

Changes:
- Add ci.yml triggered on push to master and on pull_request.
- build job: install, generate protos, check-types, lint
  (blocking).
- test job: run the mocha unit suite with continue-on-error,
  since it is flaky in CI and should signal without gating.

Impact: every push and PR now gets typecheck and lint coverage.
Copilot AI review requested due to automatic review settings May 18, 2026 22:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes proto code generation more resilient when grpc-tools’ bundled protoc binary is missing, and introduces a new CI workflow to run proto generation, typechecking, and linting on pushes/PRs.

Changes:

  • Add resolveProtoc() fallback chain in scripts/build-proto.mjs (bundled grpc-tools → PATH lookup → protoc --version).
  • Add .github/workflows/ci.yml to run npm run protos, check-types, lint, plus non-blocking unit tests on push/PR.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
scripts/build-proto.mjs Adds fallback resolution for protoc to avoid hard failures when the bundled binary is missing.
.github/workflows/ci.yml Adds CI workflow for proto generation, typecheck, lint, and non-blocking unit tests on push/PR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/build-proto.mjs
Comment on lines +67 to 70
const PROTOC = resolveProtoc()

const PROTO_DIR = path.resolve("proto")
const TS_OUT_DIR = path.resolve("src/shared/proto")
Comment thread .github/workflows/ci.yml
Comment on lines +28 to +30
- name: Generate Protocol Buffers
run: npm run protos

Patches from the critic review of PR #33:

- ci.yml: drop the redundant "Generate Protocol Buffers" step in
  the build job — `check-types` already runs `npm run protos`.
- ci.yml: add a concurrency group (cancel superseded runs),
  `permissions: contents: read`, and `timeout-minutes` on both
  jobs.
- ci.yml: rename the test job "Unit Tests (non-blocking)" so the
  continue-on-error behaviour is explicit rather than implied.
- build-proto.mjs: warn when falling back to a system protoc so
  a version divergence from grpc-tools is visible in the log.
The first CI run exposed a pre-existing bootstrap defect: the
`cli` workspace has a `prepare` script that builds (and runs
tsc) during `npm install`, which fails before protos exist.

Approach: install with `--ignore-scripts` so the cli prepare
build does not run at install time, install a system protoc
(grpc-tools' postinstall is skipped too), then generate protos
and run the checks in the correct order.

Changes:
- Both jobs: `npm install --ignore-scripts`.
- Both jobs: add an "Install protoc" step (apt protobuf-compiler)
  so build-proto.mjs has a protoc to fall back to.
Context: npm --ignore-scripts does not suppress prepare for local
workspace packages (known npm v7+ behaviour). The cli workspace
prepare runs tsc which fails before protos are generated.

Approach: split install into phases so protos exist before cli
prepare runs.

Changes:
- Phase 1: npm install --workspaces=false --ignore-scripts (root
  deps only, cli workspace not linked, no prepare triggered)
- Phase 2: sudo apt-get install protobuf-compiler + npm run protos
- Phase 3: npm install --workspace=cli (prepare now succeeds)
- Phase 4: cd webview-ui && npm install (needed for webview-ui tsc)
- Same fix applied to the test job for consistency

Impact: Typecheck & Lint job can now install and typecheck without
hitting the chicken-and-egg proto/prepare deadlock.
Remove the unused `os` import in ailiance-memory.test.ts (dead code
left from a refactor that replaced os.homedir() mocking with vi.mock).

Replace the Logger.warn/console.warn fallback pattern in
ailiance-memory.ts with a direct Logger.warn call. The fallback
was unnecessary: Logger is always available in this context, and
biome's no-console rule flags the console.warn at error level.
@electron-rare electron-rare merged commit 6a1e682 into master May 18, 2026
2 checks passed
@electron-rare electron-rare deleted the chore/protoc-resolution-and-ci branch June 1, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants