-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Export logic #9974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Export logic #9974
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
413add6
Add a firebase studio export command under an experiment flag.
christhompsongoogle 6d4bd72
typescript conversion
christhompsongoogle e7079bf
Refactored to a folder, cleaned up, tested
christhompsongoogle c74fd91
Added tests
christhompsongoogle fc3e950
Cleanup
christhompsongoogle bbd044d
Lint
christhompsongoogle 8733bba
Reorganize
christhompsongoogle 50c4dbf
Flags and comment fixes
christhompsongoogle ce74812
Lint
christhompsongoogle 9df8c7e
shrinkwrap
christhompsongoogle 7103585
Merge branch 'main' into exportLogic
christhompsongoogle 87feb76
Test fix
christhompsongoogle 15a5fe6
Merge
christhompsongoogle 7d7f83d
Merge branch 'main' into exportLogic
christhompsongoogle b6eb767
Merge branch 'main' into exportLogic
joehan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| import { Command } from "../command"; | ||
| import { logger } from "../logger"; | ||
| import { Options } from "../options"; | ||
| import { migrate } from "../firebase_studio/migrate"; | ||
| import * as path from "path"; | ||
| import * as experiments from "../experiments"; | ||
| import { FirebaseError } from "../error"; | ||
|
|
||
| export const command = new Command("studio:export") | ||
| .description("export Firebase Studio apps to continue development locally") | ||
| .action(() => { | ||
| export const command = new Command("studio:export <path>") | ||
| .description( | ||
| "Bootstrap Firebase Studio apps for migration to Antigravity. Run on the unzipped folder from the Firebase Studio download.", | ||
| ) | ||
| .option("--no-start-agy", "skip starting the Antigravity IDE after migration") | ||
| .action(async (exportPath: string, options: Options) => { | ||
| experiments.assertEnabled("studioexport", "export Studio apps"); | ||
| logger.info("Exporting Studio apps to Antigravity..."); | ||
| // TODO: implement export logic | ||
| if (!exportPath) { | ||
| throw new FirebaseError("Must specify a path for migration.", { exit: 1 }); | ||
| } | ||
| const rootPath = path.resolve(exportPath); | ||
| logger.info(`Exporting Studio apps from ${rootPath} to Antigravity...`); | ||
| await migrate(rootPath, { noStartAgy: !options.startAgy }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { expect } from "chai"; | ||
| import * as fs from "fs/promises"; | ||
| import * as path from "path"; | ||
| import * as sinon from "sinon"; | ||
| import { migrate } from "./migrate"; | ||
| import * as apphosting from "../gcp/apphosting"; | ||
| import * as prompt from "../prompt"; | ||
|
|
||
| describe("migrate", () => { | ||
| let sandbox: sinon.SinonSandbox; | ||
| const testRoot = "/test/root"; | ||
|
|
||
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); | ||
|
|
||
| describe("migrate", () => { | ||
| it("should perform a full migration successfully", async () => { | ||
| // Stub global fetch | ||
| const fetchStub = sandbox.stub(global, "fetch"); | ||
|
|
||
| // Mock GitHub API for skills listing | ||
| fetchStub | ||
| .withArgs("https://api.github.com/repos/firebase/agent-skills/contents/skills") | ||
| .resolves({ | ||
| ok: true, | ||
| json: async () => [ | ||
| { | ||
| name: "test-skill", | ||
| type: "dir", | ||
| url: "https://api.github.com/repos/firebase/agent-skills/contents/skills/test-skill", | ||
| }, | ||
| ], | ||
| } as any); | ||
|
|
||
| // Mock GitHub API for specific skill content | ||
| fetchStub | ||
| .withArgs("https://api.github.com/repos/firebase/agent-skills/contents/skills/test-skill") | ||
| .resolves({ | ||
| ok: true, | ||
| json: async () => [], | ||
| } as any); | ||
|
|
||
| // Mock GitHub API for Genkit skill content | ||
| fetchStub | ||
| .withArgs( | ||
| "https://api.github.com/repos/genkit-ai/skills/contents/skills/developing-genkit-js?ref=main", | ||
| ) | ||
| .resolves({ | ||
| ok: true, | ||
| json: async () => [], | ||
| } as any); | ||
|
|
||
| // Mock filesystem | ||
| sandbox.stub(fs, "readFile").callsFake(async (p: any) => { | ||
| const pStr = p.toString(); | ||
|
Check warning on line 60 in src/firebase_studio/migrate.spec.ts
|
||
| if (pStr.endsWith("metadata.json")) { | ||
| return JSON.stringify({ projectId: "test-project", appName: "Test App" }); | ||
| } | ||
| if (pStr.endsWith("readme_template.md")) { | ||
| return "# ${appName}\nExport Date: ${exportDate}\n${blueprintContent}"; | ||
| } | ||
| if (pStr.endsWith("system_instructions_template.md")) { | ||
| return "Project: ${appName}"; | ||
| } | ||
| if (pStr.endsWith("startup_workflow.md")) { | ||
| return "Step 1: Build"; | ||
| } | ||
| if (pStr.endsWith(".firebaserc")) { | ||
| return JSON.stringify({ projects: { default: "test-project" } }); | ||
| } | ||
| if (pStr.endsWith("blueprint.md")) { | ||
| return "# **App Name**: Test App\nSome blueprint content"; | ||
| } | ||
| throw new Error(`Unexpected readFile: ${pStr}`); | ||
| }); | ||
|
|
||
| sandbox.stub(fs, "writeFile").resolves(); | ||
| sandbox.stub(fs, "mkdir").resolves(); | ||
| sandbox.stub(fs, "unlink").resolves(); | ||
| sandbox.stub(fs, "readdir").resolves([]); | ||
| sandbox.stub(fs, "access").rejects({ code: "ENOENT" }); | ||
|
|
||
| // Mock App Hosting backends | ||
| sandbox.stub(apphosting, "listBackends").resolves({ | ||
| backends: [ | ||
| { | ||
| name: "projects/test-project/locations/us-central1/backends/studio", | ||
| uri: "example.com", | ||
| servingLocality: "GLOBAL_ACCESS", | ||
| labels: {}, | ||
| createTime: "", | ||
| updateTime: "", | ||
| }, | ||
| ] as any[], | ||
| unreachable: [], | ||
| }); | ||
|
|
||
| // Mock prompt | ||
| sandbox.stub(prompt, "confirm").resolves(false); | ||
|
|
||
| // Mock execSync | ||
| const childProcess = require("child_process"); | ||
| sandbox.stub(childProcess, "execSync").returns(Buffer.from("1.0.0")); | ||
|
|
||
| await migrate(testRoot); | ||
|
|
||
| // Verify key files were written | ||
| const writeStub = fs.writeFile as sinon.SinonStub; | ||
|
|
||
| expect(writeStub.calledWith(path.join(testRoot, ".firebaserc"), sinon.match(/test-project/))) | ||
| .to.be.true; | ||
| expect( | ||
| writeStub.calledWith( | ||
| path.join(testRoot, "firebase.json"), | ||
| sinon.match(/"backendId": "studio"/), | ||
| ), | ||
| ).to.be.true; | ||
| expect(writeStub.calledWith(path.join(testRoot, "README.md"), sinon.match(/Test App/))).to.be | ||
| .true; | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repository style guide advises against using
anyas an escape hatch. This type assertion is used multiple times in this test file (e.g., lines 35, 42, 49, 52, 85), which bypasses type safety.Please define proper interfaces/types or use type guards. For mocking
fetchresponses, you could useas unknown as Responseor define a partial mock object that satisfies theResponseinterface.References
anyorunknownas an escape hatch. Define proper interfaces/types or use type guards. (link)