The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { expect } from "e2e"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FileSystem from "effect/FileSystem"; |
| 4 | import * as Path from "effect/Path"; |
| 5 | |
| 6 | import { T3_HOME } from "../e2e.config.ts"; |
| 7 | import { run } from "./shell.ts"; |
| 8 | import { makeState, runPromise, test, WEB } from "./t3.ts"; |
| 9 | |
| 10 | // Stand in for the Azure CLI upstream. The real tracker builds WIQL and decodes its rows. |
| 11 | const azureCli = String.raw`#!/usr/bin/env node |
| 12 | import { existsSync, readFileSync } from "node:fs"; |
| 13 | |
| 14 | const args = process.argv.slice(2); |
| 15 | const argument = (name) => args[args.indexOf(name) + 1]; |
| 16 | const changed = existsSync(new URL("./workflow-changed", import.meta.url)); |
| 17 | const bugFinished = changed ? "Released" : "Done"; |
| 18 | const item = (id, type, title, state) => ({ |
| 19 | id, |
| 20 | url: "https://dev.azure.com/scenario/_apis/wit/workItems/" + id, |
| 21 | fields: { |
| 22 | "System.Title": title, |
| 23 | "System.State": state, |
| 24 | "System.TeamProject": "Release", |
| 25 | "System.WorkItemType": type, |
| 26 | "System.CreatedDate": "2026-10-01T00:00:00Z", |
| 27 | "System.ChangedDate": "2026-10-02T00:00:00Z", |
| 28 | }, |
| 29 | }); |
| 30 | const items = [ |
| 31 | item(7, "Bug", "Verify the release package", changed ? "Released" : "Active"), |
| 32 | item(6, "Task", changed ? "Release notes checked" : "Release notes drafted", "Closed"), |
| 33 | ]; |
| 34 | let output; |
| 35 | switch (argument("--resource")) { |
| 36 | case "workitemtypes": |
| 37 | output = { value: [ |
| 38 | { name: "Bug", states: [ |
| 39 | { name: "Active", category: "InProgress" }, |
| 40 | { name: bugFinished, category: "Completed" }, |
| 41 | ] }, |
| 42 | { name: "Task", states: [{ name: "Closed", category: "Completed" }] }, |
| 43 | ] }; |
| 44 | break; |
| 45 | case "wiql": { |
| 46 | const { query } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); |
| 47 | const clause = /\[System\.State\] (NOT )?IN \(([^)]+)\)/.exec(query); |
| 48 | const names = clause?.[2].match(/'[^']*'/g) ?? []; |
| 49 | output = { workItems: items.filter((item) => { |
| 50 | if (!clause) return true; |
| 51 | const listed = names.includes("'" + item.fields["System.State"].toLowerCase() + "'"); |
| 52 | return clause[1] ? !listed : listed; |
| 53 | }).map(({ id }) => ({ id })) }; |
| 54 | break; |
| 55 | } |
| 56 | case "workitemsbatch": { |
| 57 | const { ids } = JSON.parse(readFileSync(argument("--in-file"), "utf8")); |
| 58 | output = { value: items.filter(({ id }) => ids.includes(id)) }; |
| 59 | break; |
| 60 | } |
| 61 | default: |
| 62 | if (args[0] === "repos" && args[1] === "show") { |
| 63 | output = { |
| 64 | name: "release", |
| 65 | project: { name: "Release" }, |
| 66 | webUrl: "https://dev.azure.com/scenario/Release/_git/release", |
| 67 | remoteUrl: "https://dev.azure.com/scenario/Release/_git/release", |
| 68 | sshUrl: "git@ssh.dev.azure.com:v3/scenario/Release/release", |
| 69 | }; |
| 70 | break; |
| 71 | } |
| 72 | process.exit(1); |
| 73 | } |
| 74 | console.log(JSON.stringify(output)); |
| 75 | `; |
| 76 | |
| 77 | test( |
| 78 | "Refreshing Closed issues picks up a new Azure DevOps finished state", |
| 79 | WEB, |
| 80 | async ({ t3, app, screen }) => { |
| 81 | const workspace = await t3.project("demo"); |
| 82 | const { repository, changed } = await runPromise( |
| 83 | Effect.gen(function* () { |
| 84 | const path = yield* Path.Path; |
| 85 | const fs = yield* FileSystem.FileSystem; |
| 86 | const shim = path.join(T3_HOME, "bin", "az"); |
| 87 | yield* fs.writeFileString(shim, azureCli); |
| 88 | yield* fs.chmod(shim, 0o755); |
| 89 | return { |
| 90 | repository: path.join(T3_HOME, "release"), |
| 91 | changed: path.join(T3_HOME, "bin", "workflow-changed"), |
| 92 | }; |
| 93 | }), |
| 94 | ); |
| 95 | await runPromise(run("git", ["clone", "--quiet", workspace, repository])); |
| 96 | await runPromise( |
| 97 | run( |
| 98 | "git", |
| 99 | ["remote", "set-url", "origin", "https://dev.azure.com/scenario/Release/_git/release"], |
| 100 | { |
| 101 | cwd: repository, |
| 102 | }, |
| 103 | ), |
| 104 | ); |
| 105 | const primary = makeState(T3_HOME); |
| 106 | await runPromise(primary.cli(["project", "add", repository, "--title", "Release"])); |
| 107 | try { |
| 108 | await t3.open("/issues?status=closed"); |
| 109 | // The initial Closed list warms the workflow cache. |
| 110 | await screen.getByText("Release notes drafted", { exact: true }).waitFor({ timeout: 60_000 }); |
| 111 | await runPromise( |
| 112 | Effect.flatMap(FileSystem.FileSystem, (fs) => fs.writeFileString(changed, "")), |
| 113 | ); |
| 114 | |
| 115 | await screen.getByRole("button", "Refresh issues", { exact: true }).tap(); |
| 116 | // This title changes with the workflow, so the next assertion sees the completed refresh. |
| 117 | await screen.getByText("Release notes checked", { exact: true }).waitFor(); |
| 118 | await app.screenshot("closed-issues-after-workflow-change"); |
| 119 | await expect(screen.getByText("Verify the release package", { exact: true })).toBeVisible(); |
| 120 | } finally { |
| 121 | await runPromise(primary.cli(["project", "remove", repository, "--force"])); |
| 122 | } |
| 123 | }, |
| 124 | ); |