Skip to content

Commit df66ffd

Browse files
authored
chore(gen2-migration): e2e fixes (#14771)
* refactor(amplify-gen2-migration-e2e-system): auto-sanitize snapshots and add gen2-migration skill Move sanitize and snapshot capture logic into the e2e-system package so that sanitization runs automatically as part of the E2E flow. Simplify the migration-apps sanitize.ts and snapshot.ts to delegate to the shared implementation. Add a gen2-migration development skill with context references and a development loop for bug fixes and new features. Minor fixes to gitignore generator and refactor output directory. --- Prompt: we are working on the gen2-migration skill and e2e snapshot capture improvements * docs: refine gen2-migration skill and add E2E step to app workflows Streamline the gen2-migration skill with structured Context and Development Loop sections covering bug fix and feature workflows. Add missing E2E snapshot capture step to "Adding an App" and "Modifying an App" sections in the migration apps README. --- Prompt: refine the gen2-migration skill and fix missing E2E step in migration apps README * refactor(amplify-gen2-migration-e2e-system): simplify App class Remove git wrapper methods and call this.git.* directly. Move migrate() next to the other migration methods. Reorganize class sections (Tests, Hooks). Filter updateSnapshots to only copy _snapshot directories. --- Prompt: commit * chore: add deploy scripts, fix docs, update PR template Add deploy npm script to all migration apps. Fix snapshot.ts usage string and README to match new argument signature. Add JSDoc to new public members. Update PR template headings to h3. Update AGENTS.md PR body instructions with grouping guidance. --- Prompt: add deploy script to all apps, check for outdated docstrings, update PR template and AGENTS.md * feat(amplify-gen2-migration-e2e-system): add shared-data validation to e2e refactor flow Add cross-generation data validation tests that verify stateful resources (Cognito, AppSync/DynamoDB, S3) are correctly shared between gen1 and gen2 after migration refactor. Changes: - New shared-data.test.ts for discussions app that tests both gen1→gen2 and gen2→gen1 data access for auth, API, activity tables, and storage. - Generalize post-refactor script: extract addTableNameToTable helper, add bookmarks table support, add uncommentS3BucketName. - Make configureAmplify() lazy so tests can switch between gen1 and gen2 configs at runtime. - Propagate ENV_NAME env var from e2e system to migration scripts instead of using default parameter values. - Add testSharedData step to the e2e deploy phase. - Make Git.run public so App can cherry-pick files across branches. --- Prompt: commit everything * chore(amplify-gen2-migration-e2e-system): add test:shared-data script to all migration apps Add a no-op test:shared-data script ("true") to every migration app that doesn't already have one. This ensures the e2e system can uniformly call the script across all apps without failures. Real tests will be added per-app later. --- Prompt: Add a "test:shared-data" script to all migration apps, have it just be "true" for now, we'll add tests later. * docs(amplify-gen2-migration-e2e-system): improve skill and app workflow docs Update gen2-migration SKILL.md to clarify snapshot directory inspection and to guide the agent to check for existing test app coverage before fixing a bug. Update amplify-migration-apps README.md to include validation test steps when adding or modifying apps, and note that E2E failures require fixing the bug before snapshots can be captured. --- Prompt: made more changes. commit. * feat(amplify-gen2-migration-e2e-system): add mood-board post-push hook and analytics test Add post-push.ts for mood-board that updates KINESIS_STREAM_NAME in src/constants.ts to match the deployed environment. Add a Kinesis record/read test in analytics.test.ts that writes events and polls getKinesisEvents to verify at least one is readable. Move the getKinesisEvents parseable JSON test from analytics to api.test.ts. Fix env name generation to always use length 10. --- Prompt: made more changes. commit everything.
1 parent 3daee12 commit df66ffd

25 files changed

Lines changed: 477 additions & 56 deletions

File tree

.kiro/skills/gen2-migration/SKILL.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ with a specific combination of Amplify categories and configurations. See
3939

4040
### Fix a Bug
4141

42-
The snapshot inputs (`_snapshot.pre.*`) don't change — only the code and possibly the
43-
expected outputs (`_snapshot.post.*`) change.
44-
4542
1. Read the relevant Context above for the area you're touching.
4643

47-
2. Analyze the bug by reading the affected app's snapshot files. Read the
48-
`_snapshot.pre.generate/` and/or `_snapshot.pre.refactor/` files to understand the
49-
input configuration, and the `_snapshot.post.*` files to identify what's wrong in the
50-
current output.
44+
2. Determine whether an existing test app covers the bug's scenario. Read the affected
45+
app's `_snapshot.pre.generate/` and/or `_snapshot.pre.refactor/` files to understand
46+
the input configuration, and the `_snapshot.post.*` files to identify what's wrong in
47+
the current output. If no existing app exercises the affected code path, follow the
48+
"Adding an App" or "Modifying an App" instructions from `amplify-migration-apps/README.md`
49+
to add or update the `_snapshot.pre.*` inputs before proceeding.
5150

5251
3. Reproduce the bug by running the appropriate E2E test:
5352

@@ -56,8 +55,11 @@ expected outputs (`_snapshot.post.*`) change.
5655
npm run test:e2e
5756
```
5857

59-
After the E2E run, inspect the live Gen1 and Gen2 resources and CloudFormation stack
60-
events using the AWS CLI to confirm the root cause.
58+
The E2E tool logs the directory where on-the-fly snapshots are captured for this run
59+
(look for the `Snapshot directory:` line in the output). You can inspect the files in
60+
that directory to see the state of the app at each step. In addition, inspect the live
61+
Gen1 and Gen2 resources and CloudFormation stack events using the AWS CLI to confirm
62+
the root cause.
6163

6264
4. Present the root cause analysis to the user.
6365

@@ -111,6 +113,12 @@ expected outputs (`_snapshot.post.*`) change.
111113
UPDATE_SNAPSHOTS=1 npm run test:e2e
112114
```
113115

116+
The E2E tool logs the directory where on-the-fly snapshots are captured for this run
117+
(look for the `Snapshot directory:` line in the output). You can inspect the files in
118+
that directory to see the state of the app at each step. In addition, inspect the live
119+
Gen1 and Gen2 resources and CloudFormation stack events using the AWS CLI to confirm
120+
correctness.
121+
114122
8. Run `yarn build && yarn test` in `packages/amplify-cli/` to verify nothing else broke.
115123
If tests fail at this point, only test code changes should be needed — the production
116124
code was already validated by the E2E run.

amplify-migration-apps/README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,27 +293,36 @@ Make sure to follow the existing patterns and add tests as well.
293293
2. Run `amplify init`.
294294
3. Configure the backend using Gen1 CLI.
295295
4. Run `amplify push`.
296-
5. Use the [Snapshot Capture Tool](#snapshot-capture-tool) to capture the `pre.generate` snapshot.
296+
5. Add validation tests under `<app-name>/tests/` that exercise the new app's capabilities
297+
(API queries, auth flows, storage operations, etc.). Follow the patterns in existing apps
298+
like `project-boards/tests/` or `fitness-tracker/tests/`.
299+
6. Use the [Snapshot Capture Tool](#snapshot-capture-tool) to capture the `pre.generate` snapshot.
297300

298301
```console
299302
npx tsx snapshot.ts pre.generate <app-name>
300303

301-
6. Run `UPDATE_SNAPSHOTS=1 npm run test:e2e` to execute the full migration flow and capture
302-
the remaining snapshots (`post.generate`, `pre.refactor`, `post.refactor`).
304+
7. Run `UPDATE_SNAPSHOTS=1 npm run test:e2e` to execute the full migration flow and capture
305+
the remaining snapshots (`post.generate`, `pre.refactor`, `post.refactor`). The E2E may
306+
fail if the new app exercises a bug in the migration tooling. In that case the snapshots
307+
will not be updated — fix the bug first, then re-run.
303308

304309
## Modifying an App
305310

306311
1. `cd` into a specific app and run `npm run deploy`.
307312
2. Locate the deployed app directory in output logs and `cd` into it.
308313
3. Update the backend using Gen1 CLI.
309314
4. Run `amplify push`.
310-
5. Use the [Snapshot Capture Tool](#snapshot-capture-tool) to capture the `pre.generate` snapshot.
315+
5. Add or update validation tests under `<app-name>/tests/` to cover the modified
316+
capabilities. Follow the patterns in existing apps like `project-boards/tests/`.
317+
6. Use the [Snapshot Capture Tool](#snapshot-capture-tool) to capture the `pre.generate` snapshot.
311318

312319
```console
313320
npx tsx snapshot.ts pre.generate <app-name>
314321

315-
6. Run `UPDATE_SNAPSHOTS=1 npm run test:e2e` to execute the full migration flow and capture
316-
the remaining snapshots (`post.generate`, `pre.refactor`, `post.refactor`).
322+
7. Run `UPDATE_SNAPSHOTS=1 npm run test:e2e` to execute the full migration flow and capture
323+
the remaining snapshots (`post.generate`, `pre.refactor`, `post.refactor`). The E2E may
324+
fail if the app change exercises a bug in the migration tooling. In that case the
325+
snapshots will not be updated — fix the bug first, then re-run.
317326

318327
## Snapshot Testing
319328

amplify-migration-apps/backend-only/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"typecheck": "cd _snapshot.post.generate/amplify && npx tsc --noEmit",
1313
"test:gen1": "true",
1414
"test:gen2": "true",
15+
"test:shared-data": "true",
1516
"test:e2e": "cd ../../packages/amplify-gen2-migration-e2e-system && npx tsx src/cli.ts --app backend-only --profile ${AWS_PROFILE:-default}",
1617
"deploy": "cd ../../packages/amplify-gen2-migration-e2e-system && npx tsx src/cli.ts --app backend-only --step deploy --profile ${AWS_PROFILE:-default}",
1718
"pre-push": "true",

amplify-migration-apps/discussions/migration/post-refactor.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,61 @@
33
* Post-refactor script for discussions app.
44
*
55
* Applies manual edits required after `amplify gen2-migration refactor`:
6-
* 1. Add tableName to the DynamoDB table definition in backend.ts
7-
* This ensures the refactored table keeps its original name.
6+
* 1. Add tableName to the activity DynamoDB table definition in backend.ts
7+
* 2. Add tableName to the bookmarks DynamoDB table definition in backend.ts
8+
* 3. Uncomment s3Bucket.bucketName to preserve the original bucket name
89
*/
910

1011
import fs from 'fs/promises';
1112
import path from 'path';
1213

13-
async function addTableNameToActivityTable(appPath: string, envName: string): Promise<void> {
14+
async function addTableNameToTable(
15+
appPath: string,
16+
stackVar: string,
17+
tableId: string,
18+
envName: string,
19+
): Promise<void> {
1420
const backendPath = path.join(appPath, 'amplify', 'backend.ts');
1521
const content = await fs.readFile(backendPath, 'utf-8');
1622

17-
const tableName = `activity-${envName}`;
23+
const tableName = `${tableId}-${envName}`;
1824

25+
// Insert tableName as its own property line after the opening brace,
26+
// matching the indentation of the existing partitionKey property.
1927
const updated = content.replace(
20-
/new Table\(storageStack,\s*["']activity["'],\s*\{\s*partitionKey:/g,
21-
`new Table(storageStack, "activity", { tableName: "${tableName}", partitionKey:`,
28+
new RegExp(
29+
`(new Table\\(${stackVar},\\s*["']${tableId}["'],\\s*\\{\\n)(\\s*)(partitionKey:)`,
30+
),
31+
`$1$2tableName: '${tableName}',\n$2$3`,
2232
);
2333

2434
await fs.writeFile(backendPath, updated, 'utf-8');
2535
}
2636

27-
export async function postRefactor(appPath: string, envName = 'main'): Promise<void> {
28-
await addTableNameToActivityTable(appPath, envName);
37+
async function uncommentS3BucketName(appPath: string): Promise<void> {
38+
const backendPath = path.join(appPath, 'amplify', 'backend.ts');
39+
const content = await fs.readFile(backendPath, 'utf-8');
40+
41+
const updated = content.replace(
42+
/\/\/\s*(s3Bucket\.bucketName\s*=\s*['"][^'"]+['"];?)/g,
43+
'$1',
44+
);
45+
46+
await fs.writeFile(backendPath, updated, 'utf-8');
47+
}
48+
49+
export async function postRefactor(appPath: string, envName: string): Promise<void> {
50+
await addTableNameToTable(appPath, 'storageActivityStack', 'activity', envName);
51+
await addTableNameToTable(appPath, 'storageBookmarksStack', 'bookmarks', envName);
52+
await uncommentS3BucketName(appPath);
2953
}
3054

3155
async function main(): Promise<void> {
32-
const [appPath = process.cwd(), envName] = process.argv.slice(2);
33-
await postRefactor(appPath, envName);
56+
const [appPath = process.cwd()] = process.argv.slice(2);
57+
if (!process.env.ENV_NAME) {
58+
throw new Error(`Missing ENV_NAME env variable`);
59+
}
60+
await postRefactor(appPath, process.env.ENV_NAME);
3461
}
3562

3663
main().catch((error) => {

amplify-migration-apps/discussions/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"configure-schema": "./backend/configure-schema.sh",
1515
"sanitize": "tsx ../sanitize.ts",
1616
"typecheck": "cd _snapshot.post.generate/amplify && npx tsc --noEmit",
17-
"test:gen1": "APP_CONFIG_PATH=${APP_CONFIG_PATH:-src/amplifyconfiguration.json} NODE_OPTIONS='--experimental-vm-modules' jest --verbose",
18-
"test:gen2": "APP_CONFIG_PATH=${APP_CONFIG_PATH:-amplify_outputs.json} NODE_OPTIONS='--experimental-vm-modules' jest --verbose",
17+
"test:gen1": "APP_CONFIG_PATH=${APP_CONFIG_PATH:-src/amplifyconfiguration.json} NODE_OPTIONS='--experimental-vm-modules' jest --verbose --testPathIgnorePatterns='shared-data'",
18+
"test:gen2": "APP_CONFIG_PATH=${APP_CONFIG_PATH:-amplify_outputs.json} NODE_OPTIONS='--experimental-vm-modules' jest --verbose --testPathIgnorePatterns='shared-data'",
19+
"test:shared-data": "NODE_OPTIONS='--experimental-vm-modules' jest --verbose tests/shared-data.test.ts",
1920
"test:e2e": "cd ../../packages/amplify-gen2-migration-e2e-system && npx tsx src/cli.ts --app discussions --profile ${AWS_PROFILE:-default}",
2021
"deploy": "cd ../../packages/amplify-gen2-migration-e2e-system && npx tsx src/cli.ts --app discussions --step deploy --profile ${AWS_PROFILE:-default}",
2122
"pre-push": "true",

amplify-migration-apps/discussions/tests/api.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { generateClient } from 'aws-amplify/api';
33
import { getCurrentUser, signIn, signOut } from 'aws-amplify/auth';
4-
import { signUp, config } from './signup';
4+
import { signUp, configureAmplify } from './signup';
55
import {
66
getTopic, listTopics,
77
getPost, listPosts,
@@ -20,6 +20,7 @@ let username: string;
2020
let password: string;
2121

2222
beforeAll(async () => {
23+
const config = configureAmplify();
2324
const creds = await signUp(config);
2425
username = creds.username;
2526
password = creds.password;

0 commit comments

Comments
 (0)