Skip to content

Commit 6e075ce

Browse files
committed
fix(windows): port prepare script to platform-independent typescript
1 parent a824a06 commit 6e075ce

File tree

3 files changed

+62
-53
lines changed

3 files changed

+62
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lint:spellcheck": "spellchecker --quiet --files=\"docs/**/*.md\" --dictionaries=\"./.spellcheck.dict.txt\" --reports=\"spelling.json\" --plugins spell indefinite-article repeated-words syntax-mentions syntax-urls frontmatter",
1919
"tsc:compile": "tsc --project .",
2020
"lint:all": "yarn lint && yarn lint:markdown && yarn lint:spellcheck && yarn tsc:compile",
21-
"tests:ai:mocks": "./scripts/ai_mock_responses.sh && yarn ts-node ./packages/ai/__tests__/test-utils/convert-mocks.ts",
21+
"tests:ai:mocks": "yarn ts-node ./scripts/fetch_ai_mock_responses.ts && yarn ts-node ./packages/ai/__tests__/test-utils/convert-mocks.ts",
2222
"tests:jest": "jest",
2323
"tests:jest-watch": "jest --watch",
2424
"tests:jest-coverage": "jest --coverage",

scripts/ai_mock_responses.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

scripts/fetch_ai_mock_responses.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2016-present Invertase Limited & Contributors
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this library except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This script replaces mock response files for Vertex AI unit tests with a fresh
16+
// clone of the shared repository of Vertex AI test data.
17+
18+
// eslint-disable-next-line @typescript-eslint/no-require-imports
19+
import { execSync } from 'child_process';
20+
import { join } from 'path';
21+
import { existsSync } from 'fs';
22+
import { rimrafSync } from 'rimraf';
23+
24+
// Our test data repository
25+
const REPO_NAME = 'vertexai-sdk-test-data';
26+
const REPO_LINK = `https://github.com/FirebaseExtended/${REPO_NAME}.git`;
27+
const TEST_DATA_ROOT = join(__dirname, '..', 'packages', 'ai', '__tests__', 'test-utils');
28+
29+
// Get tags from repository, sorted by tag name, and coerce result to a string, then trim it
30+
const repoTags = (
31+
execSync(`git ls-remote --tags --sort=version:refname "${REPO_LINK}"`) + ''
32+
).trim();
33+
34+
// Fish out just the tag name from the last line (since they are sorted already)
35+
const latestTag = repoTags.split('/').at(-1);
36+
if (latestTag === undefined) {
37+
console.error('Unable to determine latest test data tag.');
38+
process.exit(1);
39+
}
40+
41+
// Create the test data directory based on the latest tag
42+
const cloneDirName = `${REPO_NAME}_${latestTag}`;
43+
const cloneDirPath = join(TEST_DATA_ROOT, cloneDirName);
44+
45+
// Clean out any test data that isn't the latest test data
46+
rimrafSync(TEST_DATA_ROOT, {
47+
preserveRoot: false,
48+
filter: (path: string, _) => !path.endsWith('.ts') && !path.includes(cloneDirName),
49+
});
50+
51+
// Exit if our intended latest data clone target already exists
52+
if (existsSync(cloneDirPath)) {
53+
console.log('AI mock responses data exists locally already. Exiting fetch script.');
54+
process.exit(0);
55+
}
56+
57+
// Clone the latest test data
58+
console.log(`Fetching AI mock responses data...`);
59+
execSync(
60+
`git -c advice.detachedHead=false clone --branch ${latestTag} ${REPO_LINK} ${cloneDirPath}`,
61+
);

0 commit comments

Comments
 (0)