microsoft / microsoft/lage

Hashes should be different (but are the same) when inputs differ by filename.

Open
#839 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
816
Forks
88
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
a target should NOT have the same hash if input files list differs when files do not exist.

To Reproduce
Edit TargetHashser.test.ts by adding the following 2 tests:

it("creates different hashes when file path is different for non-existing file", async () => {
    const monorepo1 = await setupFixture("monorepo-with-global-files");
    const hasher = new TargetHasher({ root: monorepo1.root, environmentGlob: [] });
    const target = createTarget(monorepo1.root, "package-a", "build");
    target.inputs = ["file1.txt"];

    const hash = await getHash(hasher, target);

    const target2 = createTarget(monorepo1.root, "package-a", "build");
    target2.inputs = ["file2.txt"];

    const hash2 = await getHash(hasher, target2);

    expect(hash).not.toEqual(hash2);

    monorepo1.cleanup();
  });

  it("creates different hashes when file path is different but file content is the same", async () => {
    const monorepo1 = await setupFixture("monorepo-with-global-files");
    const hasher = new TargetHasher({ root: monorepo1.root, environmentGlob: [] });
    const target = createTarget(monorepo1.root, "package-a", "build");
    target.inputs = ["file1.txt"];
    fs.writeFileSync(path.join(monorepo1.root, "packages", "package-a", "file1.txt"), "THIS IS CONTENT");

    const hash = await getHash(hasher, target);

    const target2 = createTarget(monorepo1.root, "package-a", "build");
    target2.inputs = ["file1.txt"];
    fs.writeFileSync(path.join(monorepo1.root, "packages", "package-a", "file2.txt"), "THIS IS CONTENT2");

    const hash2 = await getHash(hasher, target2);

    expect(hash).not.toEqual(hash2);

    monorepo1.cleanup();
  });

Run test

Expected behavior
Test to pass

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open TargetHashser.test.ts and add the two reproduction cases from the issue, then run the test. Trace the TargetHasher entry point used by those tests to determine why differing input paths produce the same hash. Done means the tests pass and hashes differ for the specified input-path cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.