Skip to content

Commit 1c58710

Browse files
committed
Avoid testing hard-coded trees due to GH Bug
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.
1 parent 52ea7a7 commit 1c58710

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

src/test/integration/node.test.ts

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { promises as fs } from 'fs';
12
import { getOctokit } from "@actions/github";
23

4+
35
import { ENV, REPO, ROOT_TEST_BRANCH_PREFIX, log } from "./env.js";
46
import { commitFilesFromBuffers } from "../../node.js";
57
import { deleteBranches } from "./util.js";
@@ -8,18 +10,23 @@ import {
810
getRefTreeQuery,
911
getRepositoryMetadata,
1012
} from "../../github/graphql/queries.js";
13+
import git from 'isomorphic-git';
14+
15+
// TODO: re-enable strict tree tests when GitHub have addressed the createRef
16+
// bug that's currently used in integration tests
17+
// See: https://github.com/orgs/community/discussions/136777
1118

1219
const octokit = getOctokit(ENV.GITHUB_TOKEN);
1320

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

16-
const TEST_TARGET_COMMIT = "fce2760017eab6d85388ed5cfdfac171559d80b3";
23+
// const TEST_TARGET_COMMIT = "fce2760017eab6d85388ed5cfdfac171559d80b3";
1724
/**
1825
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
1926
* to ensure that non-fast-forward pushes are tested
2027
*/
21-
const TEST_TARGET_COMMIT_2 = "7ba8473f02849de3b5449b25fc83c5245d338d94";
22-
const TEST_TARGET_TREE_2 = "95c9ea756f3686614dcdc1c42f7f654b684cdac2";
28+
// const TEST_TARGET_COMMIT_2 = "7ba8473f02849de3b5449b25fc83c5245d338d94";
29+
// const TEST_TARGET_TREE_2 = "95c9ea756f3686614dcdc1c42f7f654b684cdac2";
2330

2431
const BASIC_FILE_CHANGES_PATH = "foo.txt";
2532
const BASIC_FILE_CHANGES_OID = "0e23339619d605319ec4b49a0ac9dd94598eff8e";
@@ -39,8 +46,8 @@ const BASIC_FILE_CONTENTS = {
3946
log,
4047
};
4148

42-
const TEST_TARGET_TREE_WITH_BASIC_CHANGES =
43-
"a3431c9b42b71115c52bc6fbf9da3682cf0ed5e8";
49+
// const TEST_TARGET_TREE_WITH_BASIC_CHANGES =
50+
// "a3431c9b42b71115c52bc6fbf9da3682cf0ed5e8";
4451

4552
describe("node", () => {
4653
const branches: string[] = [];
@@ -87,6 +94,14 @@ describe("node", () => {
8794
}
8895
};
8996

97+
let testTargetCommit: string;
98+
/**
99+
* For tests, important that this commit is not an ancestor of TEST_TARGET_COMMIT,
100+
* to ensure that non-fast-forward pushes are tested
101+
*/
102+
let testTargetCommit2: string;
103+
let testTargetTree2: string;
104+
90105
beforeAll(async () => {
91106
const response = await getRepositoryMetadata(octokit, {
92107
owner: REPO.owner,
@@ -98,6 +113,12 @@ describe("node", () => {
98113
throw new Error("Repository not found");
99114
}
100115
repositoryId = response.id;
116+
117+
// Get recent 2 commits to perform tests on
118+
const log = await git.log({ fs, dir: process.cwd(), depth: 2 });
119+
testTargetCommit = log[1]?.oid ?? "N/A";
120+
testTargetCommit2 = log[0]?.oid ?? "N/A";
121+
testTargetTree2 = log[0]?.commit.tree ?? 'N/A';
101122
});
102123

103124
describe("commitFilesFromBuffers", () => {
@@ -120,8 +141,8 @@ describe("node", () => {
120141
},
121142
};
122143

123-
for (const [sizeName, { sizeBytes, treeOid, fileOid }] of Object.entries(
124-
SIZES_BYTES,
144+
for (const [sizeName, { sizeBytes, fileOid }] of Object.entries(
145+
SIZES_BYTES
125146
)) {
126147
it(`Can commit a ${sizeName}`, async () => {
127148
const branch = `${TEST_BRANCH_PREFIX}-${sizeName}`;
@@ -133,7 +154,7 @@ describe("node", () => {
133154
...REPO,
134155
branch,
135156
base: {
136-
commit: TEST_TARGET_COMMIT,
157+
commit: testTargetCommit,
137158
},
138159
message: {
139160
headline: "Test commit",
@@ -152,7 +173,8 @@ describe("node", () => {
152173

153174
await expectBranchHasTree({
154175
branch,
155-
treeOid,
176+
// TODO: re-enable
177+
// treeOid,
156178
file: {
157179
path: `${sizeName}.txt`,
158180
oid: fileOid,
@@ -219,14 +241,15 @@ describe("node", () => {
219241
...REPO,
220242
branch,
221243
base: {
222-
commit: TEST_TARGET_COMMIT,
244+
commit: testTargetCommit,
223245
},
224246
...BASIC_FILE_CONTENTS,
225247
});
226248

227249
await expectBranchHasTree({
228250
branch,
229-
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
251+
// TODO: re-enable
252+
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
230253
file: {
231254
path: BASIC_FILE_CHANGES_PATH,
232255
oid: BASIC_FILE_CHANGES_OID,
@@ -244,7 +267,7 @@ describe("node", () => {
244267
input: {
245268
repositoryId,
246269
name: `refs/heads/${branch}`,
247-
oid: TEST_TARGET_COMMIT_2,
270+
oid: testTargetCommit2,
248271
},
249272
});
250273

@@ -253,15 +276,16 @@ describe("node", () => {
253276
...REPO,
254277
branch,
255278
base: {
256-
commit: TEST_TARGET_COMMIT,
279+
commit: testTargetCommit,
257280
},
258281
...BASIC_FILE_CONTENTS,
259282
force: true,
260283
});
261284

262285
await expectBranchHasTree({
263286
branch,
264-
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
287+
// TODO: re-enable
288+
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
265289
file: {
266290
path: BASIC_FILE_CHANGES_PATH,
267291
oid: BASIC_FILE_CHANGES_OID,
@@ -278,7 +302,7 @@ describe("node", () => {
278302
input: {
279303
repositoryId,
280304
name: `refs/heads/${branch}`,
281-
oid: TEST_TARGET_COMMIT_2,
305+
oid: testTargetCommit2,
282306
},
283307
});
284308

@@ -288,17 +312,17 @@ describe("node", () => {
288312
...REPO,
289313
branch,
290314
base: {
291-
commit: TEST_TARGET_COMMIT,
315+
commit: testTargetCommit,
292316
},
293317
...BASIC_FILE_CONTENTS,
294-
}),
318+
})
295319
).rejects.toThrow(
296-
`Branch ${branch} exists already and does not match base`,
320+
`Branch ${branch} exists already and does not match base`
297321
);
298322

299323
await expectBranchHasTree({
300324
branch,
301-
treeOid: TEST_TARGET_TREE_2,
325+
treeOid: testTargetTree2,
302326
});
303327
});
304328

@@ -311,7 +335,7 @@ describe("node", () => {
311335
input: {
312336
repositoryId,
313337
name: `refs/heads/${branch}`,
314-
oid: TEST_TARGET_COMMIT,
338+
oid: testTargetCommit,
315339
},
316340
});
317341

@@ -320,14 +344,15 @@ describe("node", () => {
320344
...REPO,
321345
branch,
322346
base: {
323-
commit: TEST_TARGET_COMMIT,
347+
commit: testTargetCommit,
324348
},
325349
...BASIC_FILE_CONTENTS,
326350
});
327351

328352
await expectBranchHasTree({
329353
branch,
330-
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
354+
// TODO: re-enable
355+
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
331356
file: {
332357
path: BASIC_FILE_CHANGES_PATH,
333358
oid: BASIC_FILE_CHANGES_OID,
@@ -344,7 +369,7 @@ describe("node", () => {
344369
input: {
345370
repositoryId,
346371
name: `refs/heads/${branch}`,
347-
oid: TEST_TARGET_COMMIT,
372+
oid: testTargetCommit,
348373
},
349374
});
350375

@@ -360,7 +385,8 @@ describe("node", () => {
360385

361386
await expectBranchHasTree({
362387
branch,
363-
treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
388+
// TODO: re-enable
389+
// treeOid: TEST_TARGET_TREE_WITH_BASIC_CHANGES,
364390
file: {
365391
path: BASIC_FILE_CHANGES_PATH,
366392
oid: BASIC_FILE_CHANGES_OID,

0 commit comments

Comments
 (0)