diff --git a/packages/core/src/bindings/patch-generated-binding-package.ts b/packages/core/src/bindings/patch-generated-binding-package.ts index f2f4ebce..ed6f3e2a 100644 --- a/packages/core/src/bindings/patch-generated-binding-package.ts +++ b/packages/core/src/bindings/patch-generated-binding-package.ts @@ -224,12 +224,10 @@ async function ensureRootBindingIndex(outputDir: string): Promise { const rootIndexPath = path.join(outputDir, "index.ts"); try { - const existing = await readFile(rootIndexPath, "utf8"); - if (existing === ROOT_BINDING_INDEX_CONTENT) { - return; - } - - // Preserve a non-Caatinga root index if the generator starts shipping one. + // Any existing root index is preserved (whether Caatinga-authored or a + // non-Caatinga one the generator might start shipping); only an absent + // file is created. + await readFile(rootIndexPath, "utf8"); return; } catch { await writeFile(rootIndexPath, ROOT_BINDING_INDEX_CONTENT, "utf8"); diff --git a/packages/core/src/stellar-cli/probe-stellar-cli-features.test.ts b/packages/core/src/stellar-cli/probe-stellar-cli-features.test.ts index f6c56a54..f49120f0 100644 --- a/packages/core/src/stellar-cli/probe-stellar-cli-features.test.ts +++ b/packages/core/src/stellar-cli/probe-stellar-cli-features.test.ts @@ -41,3 +41,11 @@ describe("probeMissingStellarCliFeatures (live Stellar CLI)", () => { expect(parseStellarCliVersion(`stellar ${report.version}`)).toBe(report.version); }); }); + +describe("probeMissingStellarCliFeatures (below minimum version)", () => { + it("reports every required feature as missing when the CLI is below the minimum", async () => { + // Returns early without probing the binary, so this needs no live CLI. + const missing = await probeMissingStellarCliFeatures("22.0.0"); + expect(missing.sort()).toEqual([...STELLAR_CLI_REQUIRED_FEATURES].sort()); + }); +}); diff --git a/packages/core/src/stellar-cli/probe-stellar-cli-features.ts b/packages/core/src/stellar-cli/probe-stellar-cli-features.ts index 97ff5f69..ada6b468 100644 --- a/packages/core/src/stellar-cli/probe-stellar-cli-features.ts +++ b/packages/core/src/stellar-cli/probe-stellar-cli-features.ts @@ -24,7 +24,9 @@ export async function probeMissingStellarCliFeatures(version: string): Promise { - describe("parseContractId", () => { - it("should_parse_valid_contract_id", () => { - expect(parseContractId(`ContractID: ${VALID_CONTRACT_ID}`)).toBe(VALID_CONTRACT_ID); - }); - - it("should_throw_CONTRACT_ID_NOT_FOUND_when_absent", () => { - expect(() => parseContractId("no id here")).toThrow( - expect.objectContaining({ code: CaatingaErrorCode.CONTRACT_ID_NOT_FOUND }) - ); - }); - }); - - describe("parseWasmHash", () => { - it("should_parse_valid_wasm_hash", () => { - expect(parseWasmHash(`Hash: ${VALID_WASM_HASH}`)).toBe(VALID_WASM_HASH); - }); - - it("should_throw_WASM_HASH_NOT_FOUND_when_absent", () => { - expect(() => parseWasmHash("no hash here")).toThrow( - expect.objectContaining({ code: CaatingaErrorCode.WASM_HASH_NOT_FOUND }) - ); - }); - }); - - describe("parseStellarCliVersion", () => { - it("should_parse_valid_semver_from_output", () => { - expect(parseStellarCliVersion(VALID_VERSION_OUTPUT)).toBe("27.0.0"); - }); - - it("should_throw_STELLAR_CLI_VERSION_PARSE_FAILED_when_absent", () => { - expect(() => parseStellarCliVersion("no version here")).toThrow( - expect.objectContaining({ code: CaatingaErrorCode.STELLAR_CLI_VERSION_PARSE_FAILED }) - ); - }); - }); -}); diff --git a/packages/core/src/stellar-cli/stellar-cli-output-parser.ts b/packages/core/src/stellar-cli/stellar-cli-output-parser.ts deleted file mode 100644 index b651f477..00000000 --- a/packages/core/src/stellar-cli/stellar-cli-output-parser.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Unified façade for all Stellar CLI output parsers. - * - * Consumers should import from this module instead of from the individual - * parser files so that we have a single contract surface for any future - * output-format changes in the Stellar CLI. - */ - -export { parseContractId } from "./parse-contract-id.js"; -export { parseWasmHash } from "./parse-wasm-hash.js"; -export { parseStellarCliVersion } from "./version.js"; diff --git a/packages/core/src/stellar-cli/version.test.ts b/packages/core/src/stellar-cli/version.test.ts new file mode 100644 index 00000000..65fa360c --- /dev/null +++ b/packages/core/src/stellar-cli/version.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, it } from "vitest"; +import { CaatingaErrorCode } from "../errors/CaatingaError.js"; +import { parseStellarCliVersion } from "./version.js"; + +describe("parseStellarCliVersion", () => { + it("should_parse_valid_semver_from_output", () => { + expect(parseStellarCliVersion("stellar 27.0.0")).toBe("27.0.0"); + }); + + it("should_throw_STELLAR_CLI_VERSION_PARSE_FAILED_when_absent", () => { + expect(() => parseStellarCliVersion("no version here")).toThrow( + expect.objectContaining({ code: CaatingaErrorCode.STELLAR_CLI_VERSION_PARSE_FAILED }) + ); + }); +}); diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 3d245fed..20465841 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -1,6 +1,7 @@ import { createRequire } from "node:module"; -declare const __filename: string | undefined; - -const require = createRequire(typeof __filename === "string" ? __filename : import.meta.url); +// The CJS build (dist/index.cjs) rewrites import.meta.url via a tsup banner +// shim (pathToFileURL(__filename).href), so this resolves correctly in the ESM +// source, the ESM dist, and the CJS dist alike — no __filename fallback needed. +const require = createRequire(import.meta.url); export const CAATINGA_CORE_VERSION: string = require("../package.json").version;