Skip to content

Make the public data-use copy test pass in the public mirror - #1458

Open
aniruddhaadak80 wants to merge 2 commits into
CodebuffAI:mainfrom
aniruddhaadak80:fix/data-use-copy-test-public-mirror
Open

aniruddhaadak80 wants to merge 2 commits into
CodebuffAI:mainfrom
aniruddhaadak80:fix/data-use-copy-test-public-mirror

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

common/src/__tests__/freebuff-public-data-use-copy.test.ts cannot pass in this
repository. On current main (2d10aaa8d) it reports 1 pass, 5 fail. This PR
makes it 4 pass, 3 skip, 0 fail, test-only, in one file.

Why it fails

Two independent causes, both specific to this repository being a public export of
a private source tree.

1. Line endings decide the comparison (2 failures). README.md and
freebuff/cli/release/README.md failed with a diff of - Expected - 0 /
+ Received + 0 — zero changed lines, i.e. an invisible difference. The cause is
one stray \r per line:

$ git show HEAD:README.md   # the committed blob itself
blob CRLF: 117  LF: 117

$ # inside the generated block only
block CR count: 8   block LF count: 8

The blob in git is CRLF, there is no .gitattributes pinning either style, and
renderFreebuffDataUseFaqMarkdown() produces an LF-only template literal. So the
block in the file cannot equal the generated copy byte-for-byte on any platform —
this is not a Windows checkout artifact, and the block has 8 CR for its 8 LF. The
assertion was testing whoever last saved the file, not the copy it is named for.

2. Three cases read files this repository does not ship (3 failures). Plain
ENOENT:

error: ENOENT: no such file or directory, open '.../web/src/content/advanced/privacy.mdx'
error: ENOENT: no such file or directory, open '.../web/src/content/help/faq.mdx'
error: ENOENT: no such file or directory, open '.../landing-lab/src/components/sections/Faq.tsx'

CONTRIBUTING.md describes this repository as a public mirror, and
pr-hygiene.yml lists web/ among the paths that "are not part of this
repository". Those cases can never pass here, so they fail rather than skip.

What this changes

  • readRepoFile normalizes CRLF (and stray lone CR) to LF, so the assertion
    compares the copy's words.
  • The test.each table becomes per-case test.skipIf(!isInThisTree(path)), using
    the test.skipIf convention already present in this repo. In the private tree,
    where web/ and landing-lab/ do exist, all five cases run unchanged; if the
    export ever grows to include them, the cases reactivate on their own with no
    edit here.
  • One new test, line endings do not decide whether the copy matches, locks the
    normalization. It is not a tautology: with a no-op normalizer,
    normalizeLineEndings(copy.replace(/\n/g, '\r\n')) returns the CRLF string and
    fails against the LF-only renderer.

How it was tested

$ bun test src/__tests__/freebuff-public-data-use-copy.test.ts
before (main @ 2d10aaa8d) after
result 1 pass, 5 fail 4 pass, 3 skip, 0 fail

The two README cases are the regression lock — verified failing on unmodified
main before the change, passing after. Surrounding suites on the same base,
unaffected by this diff:

bun test src/util/__tests__     739 pass, 0 fail   (58 files)
bunx prettier --check common/src/__tests__/freebuff-public-data-use-copy.test.ts
                                 All matched files use Prettier code style!

Notes for the reviewer

  • Alternative to the line-ending half: converting the committed README.md and
    freebuff/cli/release/README.md to LF would also make the test pass, but that is
    a ~117-line whitespace change to two docs files and it would recur for the next
    person who saves with CRLF. Happy to switch to that approach if you would rather
    the bytes be canonical — it is a one-line change to this PR.
  • Why this was never caught: Public CI (.github/workflows/ci.yml) installs,
    builds the SDK, builds the binary and smoke-tests it. It never runs bun test, so
    a red suite in the exported tree is invisible to CI. I am not proposing a CI
    change here, but this is the second file I found in the same situation and it may
    be worth a separate look at whether common/ tests should run in public CI.
  • common/src/__tests__/free-agents.test.ts has the same cause 2, for three
    prompt-opening cases reading freebuff/web/convex/... and two
    freebuff-desktop/... files. I kept that out of this diff to keep it to one
    thing; happy to send it as a follow-up.
  • No source behavior is touched, and no web/, freebuff/web/,
    packages/internal/, packages/billing/, packages/bigquery/ or
    packages/build-tools/ path is modified.

@codebuff-team

Copy link
Copy Markdown
Contributor

Good instinct and solid execution for a narrow problem: freebuff-public-data-use-copy.test.ts can't pass here because (a) README.md carries CRLF while the renderer emits LF-only text, and (b) three cases read web//landing-lab/ paths this mirror doesn't ship. Your fix — normalize line endings in readRepoFile, and test.skipIf(!isInThisTree(path)) per case — is minimal and doesn't change behavior in a tree where those files exist, since isInThisTree would just return true there. The new regression test for the normalizer is a reasonable guard, not a tautology.

Two things worth reconsidering before this gets ported:

  1. Normalizing in the reader treats CRLF-vs-LF as a permanent fact of life rather than asking why README.md is committed as CRLF with no .gitattributes pinning a style. If that's an export artifact, a .gitattributes entry (README.md text eol=lf) fixing it at the source is more durable than normalizing forever in one test file — and it would also stop any future diff noise from unrelated line-ending flips.

  2. Converting test.each to a manual for loop changes the test's reporting shape (name, parametrization) for a fairly small reason — test.each supports conditional skip via a similar pattern, so it's worth checking if you can keep the table form and just gate the assertion body instead. Not a blocker, just a style nit a maintainer may push back on.

The PR is well-scoped (one file, test-only) and the before/after numbers are concrete and checkable. Worth a maintainer's look, possibly with the .gitattributes alternative folded in.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 30, 2026
Follow-up to review: the CRLF is not committed. Every one of these files
is stored as LF in the repository; the CRLF only appears in the working
tree, where core.autocrlf=true rewrites LF as CRLF on checkout. That is
why the failure diff shows zero changed lines while the assertion still
fails, and why fixing it in the reader treats a checkout artifact as a
permanent fact about the file.

Pinning these to eol=lf makes the working tree agree with the repository
on every platform, which is the durable fix. Scoped to just the five
asserted paths on purpose: a repo-wide `* text=auto eol=lf` would
renormalise everything and bury this in unrelated diff noise.

The reader normalisation stays as a guard so the assertion still means
"the copy matches" even on a checkout that ignores this file.
Copilot AI balanced review requested due to automatic review settings October 3, 2026 01:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aniruddhaadak80

Copy link
Copy Markdown
Author

Both points addressed, and the first one turned out to have a different cause than assumed.

1. .gitattributes — folded in, in 65b3a2b80.

Worth correcting one detail, because it changes what the fix has to be: README.md is not committed as CRLF. Every one of these files is stored as LF in the repository. The CRLF only ever appears in the working tree, where core.autocrlf=true rewrites LF as CRLF on checkout. That is the actual source of the "zero changed lines but still failing" symptom, and it is why normalising in the reader treats a checkout artifact as a permanent property of the file.

So .gitattributes is not just the more durable option here, it is the correct one: eol=lf makes the working tree agree with the repository on every platform instead of only where the attribute is respected. Added for the five asserted paths (README.md, freebuff/cli/release/README.md, web/src/content/advanced/privacy.mdx, web/src/content/help/faq.mdx, landing-lab/src/components/sections/Faq.tsx), scoped deliberately — a repo-wide * text=auto eol=lf would renormalise the whole tree and bury this in unrelated diff noise.

I kept the reader normalisation as well, so the assertion keeps meaning "the copy matches" even on a checkout that ignores the attribute.

2. test.each — leaving as a loop, one reason.

The skip condition is per row, not per suite: README.md is present in this mirror while landing-lab/ is not. test.skipIf(...) applies one boolean to the whole table, so hoisting it in front of .each would skip the README case too, which currently runs and should keep running. Gating inside the body instead would turn the skip into a silent pass, losing the honest skipped-vs-passed distinction that is the point of the change.

If Bun's test.each gains a per-row skip, this collapses back to the table form in a one-line change. Not arguing the point, just not spending a maintainer's review time on it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants