Skip to content

Commit

Permalink
Avoid testing hard-coded trees due to GH Bug (#19)
Browse files Browse the repository at this point in the history
See: https://github.com/orgs/community/discussions/136777

createRef cannot be reliably used for older commits,
so hard-coding expected commits and trees is not reliable for tests.

Avoid testing tree hashes and use most recent commits for now.
  • Loading branch information
s0 authored Aug 25, 2024
1 parent 52ea7a7 commit 6529a43
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions src/test/integration/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { promises as fs } from "fs";
import { getOctokit } from "@actions/github";

import { ENV, REPO, ROOT_TEST_BRANCH_PREFIX, log } from "./env.js";
Expand All @@ -8,18 +9,23 @@ import {
getRefTreeQuery,
getRepositoryMetadata,
} from "../../github/graphql/queries.js";
import git from "isomorphic-git";

// TODO: re-enable strict tree tests when GitHub have addressed the createRef
// bug that's currently used in integration tests
// See: https://github.com/orgs/community/discussions/136777

const octokit = getOctokit(ENV.GITHUB_TOKEN);

const TEST_BRANCH_PREFIX = `${ROOT_TEST_BRANCH_PREFIX}-node`;

const TEST_TARGET_COMMIT = "fce2760017eab6d85388ed5cfdfac171559d80b3";
// const TEST_TARGET_COMMIT = "fce2760017eab6d85388ed5cfdfac171559d80b3";
/**
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
* to ensure that non-fast-forward pushes are tested
*/
const TEST_TARGET_COMMIT_2 = "7ba8473f02849de3b5449b25fc83c5245d338d94";
const TEST_TARGET_TREE_2 = "95c9ea756f3686614dcdc1c42f7f654b684cdac2";
// const TEST_TARGET_COMMIT_2 = "7ba8473f02849de3b5449b25fc83c5245d338d94";
// const TEST_TARGET_TREE_2 = "95c9ea756f3686614dcdc1c42f7f654b684cdac2";

const BASIC_FILE_CHANGES_PATH = "foo.txt";
const BASIC_FILE_CHANGES_OID = "0e23339619d605319ec4b49a0ac9dd94598eff8e";
Expand All @@ -39,8 +45,8 @@ const BASIC_FILE_CONTENTS = {
log,
};

const TEST_TARGET_TREE_WITH_BASIC_CHANGES =
"a3431c9b42b71115c52bc6fbf9da3682cf0ed5e8";
// const TEST_TARGET_TREE_WITH_BASIC_CHANGES =
// "a3431c9b42b71115c52bc6fbf9da3682cf0ed5e8";

describe("node", () => {
const branches: string[] = [];
Expand Down Expand Up @@ -87,6 +93,14 @@ describe("node", () => {
}
};

let testTargetCommit: string;
/**
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
* to ensure that non-fast-forward pushes are tested
*/
let testTargetCommit2: string;
let testTargetTree2: string;

beforeAll(async () => {
const response = await getRepositoryMetadata(octokit, {
owner: REPO.owner,
Expand All @@ -98,6 +112,12 @@ describe("node", () => {
throw new Error("Repository not found");
}
repositoryId = response.id;

// Get recent 2 commits to perform tests on
const log = await git.log({ fs, dir: process.cwd(), depth: 2 });
testTargetCommit = log[1]?.oid ?? "N/A";
testTargetCommit2 = log[0]?.oid ?? "N/A";
testTargetTree2 = log[0]?.commit.tree ?? "N/A";
});

describe("commitFilesFromBuffers", () => {
Expand All @@ -120,7 +140,7 @@ describe("node", () => {
},
};

for (const [sizeName, { sizeBytes, treeOid, fileOid }] of Object.entries(
for (const [sizeName, { sizeBytes, fileOid }] of Object.entries(
SIZES_BYTES,
)) {
it(`Can commit a ${sizeName}`, async () => {
Expand All @@ -133,7 +153,7 @@ describe("node", () => {
...REPO,
branch,
base: {
commit: TEST_TARGET_COMMIT,
commit: testTargetCommit,
},
message: {
headline: "Test commit",
Expand All @@ -152,7 +172,8 @@ describe("node", () => {

await expectBranchHasTree({
branch,
treeOid,
// TODO: re-enable
// treeOid,
file: {
path: `${sizeName}.txt`,
oid: fileOid,
Expand Down Expand Up @@ -219,14 +240,15 @@ describe("node", () => {
...REPO,
branch,
base: {
commit: TEST_TARGET_COMMIT,
commit: testTargetCommit,
},
...BASIC_FILE_CONTENTS,
});

await expectBranchHasTree({
branch,
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
// TODO: re-enable
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
file: {
path: BASIC_FILE_CHANGES_PATH,
oid: BASIC_FILE_CHANGES_OID,
Expand All @@ -244,7 +266,7 @@ describe("node", () => {
input: {
repositoryId,
name: `refs/heads/${branch}`,
oid: TEST_TARGET_COMMIT_2,
oid: testTargetCommit2,
},
});

Expand All @@ -253,15 +275,16 @@ describe("node", () => {
...REPO,
branch,
base: {
commit: TEST_TARGET_COMMIT,
commit: testTargetCommit,
},
...BASIC_FILE_CONTENTS,
force: true,
});

await expectBranchHasTree({
branch,
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
// TODO: re-enable
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
file: {
path: BASIC_FILE_CHANGES_PATH,
oid: BASIC_FILE_CHANGES_OID,
Expand All @@ -278,7 +301,7 @@ describe("node", () => {
input: {
repositoryId,
name: `refs/heads/${branch}`,
oid: TEST_TARGET_COMMIT_2,
oid: testTargetCommit2,
},
});

Expand All @@ -288,7 +311,7 @@ describe("node", () => {
...REPO,
branch,
base: {
commit: TEST_TARGET_COMMIT,
commit: testTargetCommit,
},
...BASIC_FILE_CONTENTS,
}),
Expand All @@ -298,7 +321,7 @@ describe("node", () => {

await expectBranchHasTree({
branch,
treeOid: TEST_TARGET_TREE_2,
treeOid: testTargetTree2,
});
});

Expand All @@ -311,7 +334,7 @@ describe("node", () => {
input: {
repositoryId,
name: `refs/heads/${branch}`,
oid: TEST_TARGET_COMMIT,
oid: testTargetCommit,
},
});

Expand All @@ -320,14 +343,15 @@ describe("node", () => {
...REPO,
branch,
base: {
commit: TEST_TARGET_COMMIT,
commit: testTargetCommit,
},
...BASIC_FILE_CONTENTS,
});

await expectBranchHasTree({
branch,
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
// TODO: re-enable
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
file: {
path: BASIC_FILE_CHANGES_PATH,
oid: BASIC_FILE_CHANGES_OID,
Expand All @@ -344,7 +368,7 @@ describe("node", () => {
input: {
repositoryId,
name: `refs/heads/${branch}`,
oid: TEST_TARGET_COMMIT,
oid: testTargetCommit,
},
});

Expand All @@ -360,7 +384,8 @@ describe("node", () => {

await expectBranchHasTree({
branch,
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
// TODO: re-enable
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
file: {
path: BASIC_FILE_CHANGES_PATH,
oid: BASIC_FILE_CHANGES_OID,
Expand Down

0 comments on commit 6529a43

Please sign in to comment.