mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 09:39:25 +00:00
test(ios): exercise shell team selection directly (#134092)
This commit is contained in:
parent
328f3ef8c2
commit
5d8b7712bd
1 changed files with 17 additions and 122 deletions
|
|
@ -1,4 +1,3 @@
|
|||
// Ios Team Id tests cover ios team id script behavior.
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { chmodSync } from "node:fs";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
|
|
@ -18,81 +17,6 @@ let sharedHomeDir = "";
|
|||
let sharedHomeBinDir = "";
|
||||
let sharedFakePythonPath = "";
|
||||
const tempDirs: string[] = [];
|
||||
const runScriptCache = new Map<string, { ok: boolean; stdout: string; stderr: string }>();
|
||||
type TeamCandidate = {
|
||||
teamId: string;
|
||||
isFree: boolean;
|
||||
teamName: string;
|
||||
};
|
||||
|
||||
function parseTeamCandidateRows(raw: string): TeamCandidate[] {
|
||||
const candidates: TeamCandidate[] = [];
|
||||
for (const rawLine of raw.split("\n")) {
|
||||
const line = rawLine.replace(/\r/g, "").trim();
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
const parts = line.split("\t");
|
||||
if (parts.length < 3) {
|
||||
continue;
|
||||
}
|
||||
const teamId = parts[0] ?? "";
|
||||
if (!teamId) {
|
||||
continue;
|
||||
}
|
||||
candidates.push({
|
||||
teamId,
|
||||
isFree: (parts[1] ?? "0") === "1",
|
||||
teamName: parts[2] ?? "",
|
||||
});
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
function pickTeamIdFromCandidates(params: {
|
||||
candidates: TeamCandidate[];
|
||||
canonicalTeamId?: string;
|
||||
preferredTeamId?: string;
|
||||
preferredTeamName?: string;
|
||||
preferNonFreeTeam?: boolean;
|
||||
requireCanonical?: boolean;
|
||||
}): string | undefined {
|
||||
const canonicalTeamId = (params.canonicalTeamId ?? CANONICAL_TEAM_ID).trim();
|
||||
if (canonicalTeamId) {
|
||||
const canonical = params.candidates.find((candidate) => candidate.teamId === canonicalTeamId);
|
||||
if (canonical || params.requireCanonical) {
|
||||
return canonical?.teamId;
|
||||
}
|
||||
}
|
||||
|
||||
const preferredTeamId = (params.preferredTeamId ?? "").trim();
|
||||
if (preferredTeamId) {
|
||||
const preferred = params.candidates.find((candidate) => candidate.teamId === preferredTeamId);
|
||||
if (preferred) {
|
||||
return preferred.teamId;
|
||||
}
|
||||
}
|
||||
|
||||
const preferredTeamName = (params.preferredTeamName ?? "").trim().toLowerCase();
|
||||
if (preferredTeamName) {
|
||||
const preferredByName = params.candidates.find(
|
||||
(candidate) => candidate.teamName.trim().toLowerCase() === preferredTeamName,
|
||||
);
|
||||
if (preferredByName) {
|
||||
return preferredByName.teamId;
|
||||
}
|
||||
}
|
||||
|
||||
if (params.preferNonFreeTeam !== false) {
|
||||
const paid = params.candidates.find((candidate) => !candidate.isFree);
|
||||
if (paid) {
|
||||
return paid.teamId;
|
||||
}
|
||||
}
|
||||
|
||||
return params.candidates[0]?.teamId;
|
||||
}
|
||||
|
||||
async function writeExecutable(filePath: string, body: string): Promise<void> {
|
||||
await writeFile(filePath, body, "utf8");
|
||||
chmodSync(filePath, 0o755);
|
||||
|
|
@ -107,15 +31,6 @@ function runScript(
|
|||
stdout: string;
|
||||
stderr: string;
|
||||
} {
|
||||
const extraEnvKey = Object.keys(extraEnv)
|
||||
.toSorted((a, b) => a.localeCompare(b))
|
||||
.map((key) => `${key}=${extraEnv[key] ?? ""}`)
|
||||
.join("\u0001");
|
||||
const cacheKey = `${homeDir}\u0000${extraEnvKey}\u0000${scriptArgs.join("\u0001")}`;
|
||||
const cached = runScriptCache.get(cacheKey);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const binDir = path.join(homeDir, "bin");
|
||||
const env = {
|
||||
HOME: homeDir,
|
||||
|
|
@ -129,9 +44,7 @@ function runScript(
|
|||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
const result = { ok: true, stdout: stdout.trim(), stderr: "" };
|
||||
runScriptCache.set(cacheKey, result);
|
||||
return result;
|
||||
return { ok: true, stdout: stdout.trim(), stderr: "" };
|
||||
} catch (error) {
|
||||
const e = error as { stdout?: unknown; stderr?: unknown };
|
||||
const stdout =
|
||||
|
|
@ -146,9 +59,7 @@ function runScript(
|
|||
: Buffer.isBuffer(e.stderr)
|
||||
? e.stderr.toString("utf8")
|
||||
: "";
|
||||
const result = { ok: false, stdout: stdout.trim(), stderr: stderr.trim() };
|
||||
runScriptCache.set(cacheKey, result);
|
||||
return result;
|
||||
return { ok: false, stdout: stdout.trim(), stderr: stderr.trim() };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,41 +117,22 @@ exit 1`,
|
|||
await writeExecutable(
|
||||
sharedFakePythonPath,
|
||||
`#!/usr/bin/env bash
|
||||
printf 'AAAAA11111\\t0\\tAlpha Team\\r\\n'
|
||||
printf 'AAAAA11111\\t1\\tAlpha Team\\r\\n'
|
||||
printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`,
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
afterAll(() => {
|
||||
cleanupTempDirs(tempDirs);
|
||||
});
|
||||
|
||||
it("parses team listings and prioritizes preferred IDs without shelling out", () => {
|
||||
const rows = parseTeamCandidateRows(
|
||||
"AAAAA11111\t1\tAlpha Team\r\nBBBBB22222\t0\tBeta Team\r\n",
|
||||
);
|
||||
expect(rows).toStrictEqual([
|
||||
{ teamId: "AAAAA11111", isFree: true, teamName: "Alpha Team" },
|
||||
{ teamId: "BBBBB22222", isFree: false, teamName: "Beta Team" },
|
||||
]);
|
||||
|
||||
const preferred = pickTeamIdFromCandidates({
|
||||
candidates: rows,
|
||||
preferredTeamId: "BBBBB22222",
|
||||
it("honors a preferred free team from CRLF Xcode listings", () => {
|
||||
const result = runScript(sharedHomeDir, {
|
||||
IOS_PYTHON_BIN: sharedFakePythonPath,
|
||||
IOS_PREFERRED_TEAM_ID: "AAAAA11111",
|
||||
});
|
||||
expect(preferred).toBe("BBBBB22222");
|
||||
|
||||
const missingCanonical = pickTeamIdFromCandidates({
|
||||
candidates: rows,
|
||||
requireCanonical: true,
|
||||
});
|
||||
expect(missingCanonical).toBeUndefined();
|
||||
|
||||
const fallback = pickTeamIdFromCandidates({
|
||||
candidates: rows,
|
||||
preferredTeamId: "CCCCCC3333",
|
||||
});
|
||||
expect(fallback).toBe("BBBBB22222");
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.stdout).toBe("AAAAA11111");
|
||||
});
|
||||
|
||||
it("prefers the canonical OpenClaw iOS team when it is present", async () => {
|
||||
|
|
@ -293,10 +185,13 @@ echo '{}'`,
|
|||
expect(result.stdout).toBe(CANONICAL_TEAM_ID);
|
||||
});
|
||||
|
||||
it("resolves a fallback team ID from Xcode team listings (smoke)", () => {
|
||||
const fallbackResult = runScript(sharedHomeDir, { IOS_PYTHON_BIN: sharedFakePythonPath });
|
||||
expect(fallbackResult.ok).toBe(true);
|
||||
expect(fallbackResult.stdout).toBe("AAAAA11111");
|
||||
it("falls back to a paid Xcode team when the preferred ID is unavailable", () => {
|
||||
const result = runScript(sharedHomeDir, {
|
||||
IOS_PYTHON_BIN: sharedFakePythonPath,
|
||||
IOS_PREFERRED_TEAM_ID: "CCCCCC3333",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.stdout).toBe("BBBBB22222");
|
||||
});
|
||||
|
||||
it("fails canonical-only resolution when only fallback teams are available", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue