Skip to content

feat(bun): pathExists, a total existence check for the Bun host profile - #793

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/stat-missing-path
Nov 14, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
fix/stat-missing-path

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

statIsFile and statIsDirectory throw ENOENT on a missing path, and host_profile pins that contract. That leaves a Bun-ESM program no way to ask "does this path exist?" without crashing on the answer "no". kyX (metadatastician/kyx) needs exactly that check before it reads inputs and writes outputs. Without it, a missing input gives an uncaught stack trace and the wrong exit status.

Changes

  • lib/codegen_deno.ml: new Bun builtin pathExists → fs.existsSync(path). It is true for any existing path, false for a missing one, and never throws. The stat predicates are unchanged; I chose not to flip their pinned ENOENT contract.
  • stdlib/Deno.affine: pub extern fn pathExists(path: String) -> Bool, declared beside the stat externs, which is what the builtins↔stdlib consistency test requires.
  • tests/codegen-bun/host_profile.{affine,harness.mjs}: pathExists is false for the removed file and true for a directory.

Testing

  • tools/run_codegen_bun_tests.sh: fails without the builtin, passes with it (2 harnesses).
  • dune build @test/runtest: green, 570 tests.

Generated by Claude Code

statIsFile and statIsDirectory throw ENOENT on a missing path, and
host_profile pins that contract, so a program has no way to ask "is it
there?" without crashing on the answer "no". kyX (metadatastician/kyx)
needs exactly that before reading its inputs and writing its outputs, to
exit with its documented usage status instead of an uncaught stack trace.

pathExists lowers to fs.existsSync: true for any existing path, false for a
missing one, never a throw. The stat predicates are unchanged. It is
declared in stdlib/Deno.affine beside them (the builtins<->stdlib
consistency test requires the declaration), and host_profile now asserts
pathExists is false for the removed file and true for a directory.

Tests: tools/run_codegen_bun_tests.sh fails without the builtin and passes
with it; dune build @test/runtest is green (570 tests).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZnvMV5Ghe7LUf3oc6N
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added a path existence check that returns whether a file or directory exists, without throwing an error for missing paths.

The Deno standard-library bindings add pathExists(path), and Bun code generation lowers it to existsSync(path). The Bun host-profile fixture checks that the wrapper returns false for a missing file and true for an existing directory.

Changes: Bun path existence check

Layer / File(s) Summary
Bind and test pathExists
stdlib/Deno.affine, lib/codegen_deno.ml, tests/codegen-bun/host_profile.affine, tests/codegen-bun/host_profile.harness.mjs
Adds the public binding and Bun lowering. The test fixture exposes exists(path) and checks its results for a missing file and an existing directory.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: metadatastician

Merge Risk: Minimal · up to ab5de

This adds a non-throwing path existence check for the Bun host profile. It is a small additive change with tests for missing and existing paths, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a new Bun host-profile builtin, pathExists, that checks path existence without throwing. The raw summary, objectives and description all describe this same change, so …
Description check Passed The description explains the motivation (stat predicates throw ENOENT, so a total existence check is needed), lists the changes to lib/codegen_deno.ml, stdlib/Deno.affine and the host_profile tests, a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a new Bun host-profile builtin, pathExists, that checks path existence without throwing. The raw summary, objectives and description all describe this same change, so the title matches the changeset.

Full details: Description check

Explanation

The description explains the motivation (stat predicates throw ENOENT, so a total existence check is needed), lists the changes to lib/codegen_deno.ml, stdlib/Deno.affine and the host_profile tests, and reports test results. It is directly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1c61d630-716c-4e3f-97b5-a7f89de81fa7
Commits

Reviewing files that changed from the base of the PR and between 9799f1d and ab5ded0.

Files selected for processing: 4

  • lib/codegen_deno.ml
  • stdlib/Deno.affine
  • tests/codegen-bun/host_profile.affine
  • tests/codegen-bun/host_profile.harness.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional comments: 1

stdlib/Deno.affine: 1

83-83: Functional Correctness

The standalone mirror is not in this checkout, so there is no export to add.

The comment assumes that packages/affine-deno/mod.js exists and must export every binding in stdlib/Deno.affine. The file does not exist here, and the audit document records the package as not yet created. The new pathExists declaration therefore does not break a standalone consumer that the checkout can provide.

@sonarqubecloud

Copy link
Copy Markdown

@linear-code
linear-code Bot marked this pull request as ready for review November 14, 2026 21:39
@hyperpolymath
hyperpolymath merged commit fe37b37 into main Nov 14, 2026
11 checks passed
@hyperpolymath
hyperpolymath deleted the fix/stat-missing-path branch November 14, 2026 22:12
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.

3 participants