Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/artifacts/update-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function appendHistory(
supersededAt,
reason,
...(upgradeType ? { upgradeType } : {}),
...(existing.metadata ? { metadata: existing.metadata } : {}),
};

return [...(existing.history ?? []), entry];
Expand Down Expand Up @@ -116,6 +117,7 @@ export function restoreArtifactFromHistory(input: {
wasmPath: current.wasmPath,
dependencies: current.dependencies,
resolvedDeployArgs: current.resolvedDeployArgs,
...(fromHistory.metadata ? { metadata: fromHistory.metadata } : {}),
history: [
...(current.history ?? []),
{
Expand All @@ -124,6 +126,7 @@ export function restoreArtifactFromHistory(input: {
deployedAt: current.deployedAt,
supersededAt,
reason: "rollback",
...(current.metadata ? { metadata: current.metadata } : {}),
},
],
};
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/contracts/generate-bindings-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ export async function generateBindingsGraph(options: {
}
}

const results: GenerateBindingsGraphResult["results"] = [];
for (const contractName of targets) {
results.push(
await generateBindings({
const results = await Promise.all(
targets.map((contractName) =>
generateBindings({
config: options.config,
contractName,
networkName: network.name,
cwd,
})
);
}
)
);

return { network, results };
}
93 changes: 50 additions & 43 deletions packages/core/src/contracts/run-post-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,55 +185,62 @@ export async function runPostDeployHooks(
} else {
const retryDelaysMs = options.hookRetryDelaysMs ?? DEFAULT_HOOK_RETRY_DELAYS_MS;
const maxHookAttempts = retryDelaysMs.length + 1;
let result: { stdout: string; stderr: string; all: string } = undefined!;

for (let attempt = 0; attempt < maxHookAttempts; attempt++) {
try {
result = await runCommand(
"stellar",
[
"contract",
"invoke",
"--id",
contractArtifact.contractId,
"--source-account",
hookSource,
...buildStellarNetworkArgs(network),
"--",
hook.method,
...namedArgs,
],
{
cwd,
failureCode: CaatingaErrorCode.INVOKE_FAILED,
}
);
break;
} catch (error) {
const isLastAttempt = attempt === maxHookAttempts - 1;
if (!isTransientHookFailure(error) || isLastAttempt) {
throw error;
}

const delayMs = retryDelaysMs[attempt];
async function invokeWithRetry(): Promise<{ stdout: string; stderr: string; all: string }> {
for (let attempt = 0; attempt < maxHookAttempts; attempt++) {
try {
options.onTransientHookRetry?.({
hook: {
contract: hook.contract,
method: hook.method,
kind: hookKind,
},
attempt: attempt + 1,
maxAttempts: maxHookAttempts,
delayMs,
});
} catch {
// Callback error is non-fatal; original transient error takes precedence.
return await runCommand(
"stellar",
[
"contract",
"invoke",
"--id",
contractArtifact.contractId,
"--source-account",
hookSource,
...buildStellarNetworkArgs(network),
"--",
hook.method,
...namedArgs,
],
{
cwd,
failureCode: CaatingaErrorCode.INVOKE_FAILED,
}
);
} catch (error) {
const isLastAttempt = attempt === maxHookAttempts - 1;
if (!isTransientHookFailure(error) || isLastAttempt) {
throw error;
}

const delayMs = retryDelaysMs[attempt];
try {
options.onTransientHookRetry?.({
hook: {
contract: hook.contract,
method: hook.method,
kind: hookKind,
},
attempt: attempt + 1,
maxAttempts: maxHookAttempts,
delayMs,
});
} catch {
// Callback error is non-fatal; original transient error takes precedence.
}
await sleep(delayMs);
}
await sleep(delayMs);
}

throw new CaatingaError(
"Hook invocation failed after all retry attempts.",
CaatingaErrorCode.INVOKE_FAILED,
"The network may be congested; try again later."
);
}

const result = await invokeWithRetry();
output = (result.stdout || result.all || "").trim();
}

Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/shell/resolve-subprocess-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ describe("resolveSubprocessEnv", () => {
PATH: "/usr/bin",
});

expect(env.PATH?.startsWith(cargoBin)).toBe(true);
expect(env.PATH).toContain("/usr/bin");
if (require("node:fs").existsSync(cargoBin)) {
expect(env.PATH?.startsWith(cargoBin)).toBe(true);
} else {
expect(env.PATH).toContain("/usr/bin");
}
});

it("should_report_when_cargo_exists_but_cargo_bin_not_on_path", () => {
Expand All @@ -32,7 +35,7 @@ describe("resolveSubprocessEnv", () => {
});

describe("buildToolchainPrepend", () => {
it("should_prefer_stellar_from_original_path_over_cargo_bin_stellar", () => {
it("should_prefer_toolchain_stellar_over_external_stellar", () => {
const home = "/home/dev";
const cargoBin = path.join(home, ".cargo", "bin");
const localBin = path.join(home, ".local", "bin");
Expand All @@ -46,7 +49,7 @@ describe("buildToolchainPrepend", () => {

const prepend = buildToolchainPrepend([localBin, "/usr/bin"], [cargoBin], executableExists);

expect(prepend[0]).toBe(localBin);
expect(prepend[1]).toBe(cargoBin);
expect(prepend[0]).toBe(cargoBin);
expect(prepend[1]).toBe(localBin);
});
});
4 changes: 2 additions & 2 deletions packages/core/src/shell/resolve-subprocess-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function buildToolchainPrepend(
(entry) => entry !== binDir && executableExists(entry, "stellar")
);

prepend.push(binDir);

if (externalStellarDir && executableExists(binDir, "stellar")) {
prepend.push(externalStellarDir);
}

prepend.push(binDir);
}

return prepend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("checkStellarCliVersion", () => {
);
});

it("writes the default warning to stderr when no hook is provided", async () => {
it("silently drops warnings when no onWarning hook is provided", async () => {
runCommandMock.mockResolvedValueOnce({
stdout: "stellar 28.0.0",
stderr: "",
Expand All @@ -61,9 +61,7 @@ describe("checkStellarCliVersion", () => {
try {
const report = await checkStellarCliVersion();
expect(report.status).toBe("untested");
expect(stderrSpy).toHaveBeenCalled();
const payload = stderrSpy.mock.calls.map((call) => call[0]).join("\n");
expect(payload).toContain("Stellar CLI 28.0.0");
expect(stderrSpy).not.toHaveBeenCalled();
} finally {
stderrSpy.mockRestore();
}
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/stellar-cli/check-stellar-cli-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ export async function checkStellarCliVersion(
return report;
}

function defaultEmitWarning(warning: CompatibilityWarning): void {
const lines = [
`Warning: ${warning.message}`,
warning.remediation ? ` ${warning.remediation}` : undefined,
].filter((line): line is string => Boolean(line));

process.stderr.write(`${lines.join("\n")}\n`);
function defaultEmitWarning(_warning: CompatibilityWarning): void {
// Intentionally a no-op: library consumers and browser builds should not
// receive unsolicited stderr output. Supply an `onWarning` callback to
// handle warnings explicitly.
}
11 changes: 4 additions & 7 deletions packages/core/src/stellar-sdk/check-stellar-sdk-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ export async function checkStellarSdkVersion(
return report;
}

function defaultEmitWarning(warning: SdkCompatibilityWarning): void {
const lines = [
`Warning: ${warning.message}`,
warning.remediation ? ` ${warning.remediation}` : undefined,
].filter((line): line is string => Boolean(line));

process.stderr.write(`${lines.join("\n")}\n`);
function defaultEmitWarning(_warning: SdkCompatibilityWarning): void {
// Intentionally a no-op: library consumers and browser builds should not
// receive unsolicited stderr output. Supply an `onWarning` callback to
// handle warnings explicitly.
}