mirror of
https://github.com/openai/codex-security.git
synced 2026-11-24 03:45:49 +08:00
test: preserve Git configuration in submodule fixtures
This commit is contained in:
@@ -32,21 +32,21 @@ describe("patch change tracking", () => {
|
||||
test.each([
|
||||
"published",
|
||||
"missing",
|
||||
"published-deinit",
|
||||
"missing-deinit",
|
||||
"published-deinit-dangling",
|
||||
"missing-deinit-dangling",
|
||||
"published-deinit-renamed",
|
||||
"missing-deinit-renamed",
|
||||
"published-deinit-renamed-other-store",
|
||||
"missing-deinit-renamed-other-store",
|
||||
"published-removed-worktree",
|
||||
"missing-removed-worktree",
|
||||
"published-removed-worktree-dangling",
|
||||
"missing-removed-worktree-dangling",
|
||||
"published-removed-worktree-renamed",
|
||||
"missing-removed-worktree-renamed",
|
||||
"published-removed-worktree-renamed-other-store",
|
||||
"missing-removed-worktree-renamed-other-store",
|
||||
"push-no",
|
||||
"submodule-false",
|
||||
])(
|
||||
"publishes assessed nested updates with %s commits/settings",
|
||||
async (mode) => {
|
||||
const missing = mode.startsWith("missing");
|
||||
const deinitialized = mode.includes("deinit");
|
||||
const worktreeRemoved = mode.includes("removed-worktree");
|
||||
const dangling = mode.endsWith("-dangling");
|
||||
const renamed = mode.includes("-renamed");
|
||||
const otherStore = mode.endsWith("-other-store");
|
||||
@@ -127,13 +127,14 @@ describe("patch change tracking", () => {
|
||||
if (mode.startsWith("published"))
|
||||
nestedGit("push", "origin", `${after}:refs/heads/main`);
|
||||
nestedIndex = await readFile(nestedIndexPath);
|
||||
if (deinitialized) {
|
||||
if (worktreeRemoved) {
|
||||
git("add", "nested");
|
||||
if (dangling) {
|
||||
nestedGit("checkout", "--detach", before);
|
||||
nestedIndex = await readFile(nestedIndexPath);
|
||||
}
|
||||
git("submodule", "deinit", "--force", "--", "nested");
|
||||
await rm(nested, { recursive: true });
|
||||
await mkdir(nested);
|
||||
if (renamed) {
|
||||
git(
|
||||
"config",
|
||||
@@ -166,13 +167,13 @@ describe("patch change tracking", () => {
|
||||
if (missing) {
|
||||
expect(outcome.stderr).toContain("--resume-pr");
|
||||
expect(outcome.stderr).toContain(
|
||||
deinitialized
|
||||
worktreeRemoved
|
||||
? "not available in its remote-tracking refs"
|
||||
: "not be found on any remote",
|
||||
);
|
||||
expect(creations).toBe(0);
|
||||
expect(git("ls-remote", "origin")).toBe("");
|
||||
if (deinitialized) {
|
||||
if (worktreeRemoved) {
|
||||
const refused = await runWorkflow(
|
||||
["patch", "--resume-pr", git("branch", "--show-current"), "--json"],
|
||||
{
|
||||
@@ -243,7 +244,7 @@ describe("patch change tracking", () => {
|
||||
expect(git("ls-remote", "origin")).toContain(git("rev-parse", "HEAD"));
|
||||
expect(git("status", "--porcelain")).toBe("");
|
||||
expect(await readFile(nestedIndexPath)).toEqual(nestedIndex);
|
||||
if (deinitialized)
|
||||
if (worktreeRemoved)
|
||||
await expect(readFile(join(nested, "app.ts"))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ describe("deinitialized patch submodule availability", () => {
|
||||
const fixtures = createTemporaryDirectories(true);
|
||||
afterEach(fixtures.cleanup);
|
||||
|
||||
async function fixture() {
|
||||
async function fixture(published = false, initialized = false) {
|
||||
const outer = await publicationRepository(fixtures);
|
||||
const { directory, git } = outer;
|
||||
const hooks = await fixtures.create("patch-submodule-hooks-");
|
||||
@@ -43,7 +43,6 @@ describe("deinitialized patch submodule availability", () => {
|
||||
const pushes: string[][] = [];
|
||||
const nativePushes: { exitCode: number; stderr: string }[] = [];
|
||||
let interruptPush = false;
|
||||
let initializedChild = false;
|
||||
let creations = 0;
|
||||
let modelRuns = 0;
|
||||
const run = (
|
||||
@@ -60,7 +59,7 @@ describe("deinitialized patch submodule availability", () => {
|
||||
interruptPush = false;
|
||||
throw new Error("Synthetic publication interruption");
|
||||
}
|
||||
if (initializedChild) {
|
||||
if (initialized) {
|
||||
// Native recursive push uses the parent's branch refspec for the child.
|
||||
const branch = arguments_.at(-1)!;
|
||||
if (
|
||||
@@ -103,16 +102,24 @@ describe("deinitialized patch submodule availability", () => {
|
||||
return onCodex(arguments_, output);
|
||||
},
|
||||
});
|
||||
const update = async (published = false, initialized = false) => {
|
||||
const commitUpdate = async () => {
|
||||
await writeFile(join(nested, "app.ts"), "fixed\n");
|
||||
inner("commit", "-am", "Synthetic nested update");
|
||||
const commit = inner("rev-parse", "HEAD");
|
||||
return inner("rev-parse", "HEAD");
|
||||
};
|
||||
let preparedCommit = "";
|
||||
if (initialized) {
|
||||
inner("branch", "--set-upstream-to", "origin/main", "main");
|
||||
} else {
|
||||
// Configuration setup precedes capture; the patch changes only the gitlink.
|
||||
preparedCommit = await commitUpdate();
|
||||
if (published) inner("push", "origin", "HEAD:main");
|
||||
git("add", "nested");
|
||||
initializedChild = initialized;
|
||||
if (initialized)
|
||||
inner("branch", "--set-upstream-to", "origin/main", "main");
|
||||
else git("submodule", "deinit", "--force", "--", "nested");
|
||||
git("submodule", "deinit", "--force", "--", "nested");
|
||||
}
|
||||
const update = async () => {
|
||||
const commit = initialized ? await commitUpdate() : preparedCommit;
|
||||
if (initialized) git("add", "nested");
|
||||
else git("update-index", "--cacheinfo", `160000,${commit},nested`);
|
||||
return commit;
|
||||
};
|
||||
return {
|
||||
@@ -211,12 +218,12 @@ describe("deinitialized patch submodule availability", () => {
|
||||
test.each([false, true])(
|
||||
"publishes an available commit with deleted current registration: %p",
|
||||
async (deleteRegistration) => {
|
||||
const current = await fixture();
|
||||
const current = await fixture(true);
|
||||
let commit = "";
|
||||
const result = await current.run(
|
||||
["patch", "Synthetic issue", "--create-pr", "--json"],
|
||||
async (_args, output) => {
|
||||
commit = await current.update(true);
|
||||
commit = await current.update();
|
||||
if (deleteRegistration)
|
||||
await rm(join(current.directory, ".gitmodules"));
|
||||
output?.stdout.write("Synthetic patch complete.");
|
||||
@@ -352,7 +359,10 @@ describe("deinitialized patch submodule availability", () => {
|
||||
"%s on initial publication and resume",
|
||||
async (_name, configuration) => {
|
||||
for (const phase of ["initial", "resume"]) {
|
||||
const current = await fixture();
|
||||
const current = await fixture(
|
||||
configuration.published,
|
||||
configuration.initialized,
|
||||
);
|
||||
for (const [key, value] of configuration.settings) {
|
||||
if (value === undefined) {
|
||||
const [section, name] = key.split(".");
|
||||
@@ -377,10 +387,7 @@ describe("deinitialized patch submodule availability", () => {
|
||||
const initial = await current.run(
|
||||
["patch", "Synthetic issue", "--create-pr", "--json"],
|
||||
async (_args, output) => {
|
||||
commit = await current.update(
|
||||
configuration.published,
|
||||
configuration.initialized,
|
||||
);
|
||||
commit = await current.update();
|
||||
output?.stdout.write("Synthetic patch complete.");
|
||||
return 0;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user