From 848a8f0552825056419db275cfce060eba891cb9 Mon Sep 17 00:00:00 2001 From: Amaad Martin Date: Mon, 3 Aug 2026 23:06:22 -0700 Subject: [PATCH] test: pin the version tests to their own manifest and a semver shape Stacked on the core/dev version tests: the equality assertion alone can pass vacuously. release-please's linked-versions plugin holds the root, core, dev and integrations manifests at the same version forever, so a read that resolved to the wrong package.json still compares equal; asserting the package name pins the read to the intended manifest. The semver match stops a future refactor that makes both sides undefined from keeping the test green. --- core/test/version_test.ts | 11 ++++++++++- dev/test/version_test.ts | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/test/version_test.ts b/core/test/version_test.ts index 2a49e02af..9e867dd09 100644 --- a/core/test/version_test.ts +++ b/core/test/version_test.ts @@ -8,11 +8,20 @@ import {version} from '@google/adk'; import {readFileSync} from 'node:fs'; import {describe, expect, it} from 'vitest'; +/** major.minor.patch, with an optional pre-release suffix. */ +const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/; + describe('version', () => { it('matches the version declared in package.json', () => { - const pkg: {version: string} = JSON.parse( + const pkg: {name: string; version: string} = JSON.parse( readFileSync(new URL('../package.json', import.meta.url), 'utf-8'), ); + + // release-please holds every workspace at the same version, so a read that + // resolved to the wrong manifest would still compare equal. Pin the name. + expect(pkg.name).toBe('@google/adk'); + // Guards against both sides being undefined, which would compare equal. + expect(version).toMatch(SEMVER_PATTERN); expect(version).toBe(pkg.version); }); }); diff --git a/dev/test/version_test.ts b/dev/test/version_test.ts index 5c01eef1a..79fa1f4d5 100644 --- a/dev/test/version_test.ts +++ b/dev/test/version_test.ts @@ -9,11 +9,20 @@ import {describe, expect, it} from 'vitest'; import {version} from '../src/version.js'; +/** major.minor.patch, with an optional pre-release suffix. */ +const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/; + describe('version', () => { it('matches the version declared in package.json', () => { - const pkg: {version: string} = JSON.parse( + const pkg: {name: string; version: string} = JSON.parse( readFileSync(new URL('../package.json', import.meta.url), 'utf-8'), ); + + // release-please holds every workspace at the same version, so a read that + // resolved to the wrong manifest would still compare equal. Pin the name. + expect(pkg.name).toBe('@google/adk-devtools'); + // Guards against both sides being undefined, which would compare equal. + expect(version).toMatch(SEMVER_PATTERN); expect(version).toBe(pkg.version); }); });