App Privacy stopped at "now click Get Started yourself" and every page asked the owner to click Next. The owner should not click what storebound can safely do. - Every button of every console form is classified (navigation, draft-save, final-submit) in FORM_BUTTONS (cli/lib/console-forms.ts), citing Apple's and Google's help pages. A scoped flow gate (flowAllowed) lets navigation through; the generic click gate stays absolute for field clicks. - App Privacy: Get Started, Edit next to Data Types (never the Privacy Policy Edit), each data type / "Set Up <type>", Next, and the Save inside the questionnaire dialogs (a draft: Apple publishes only after Publish, per "Manage app privacy"). Each type's dialog may be one page or purposes > Next > linked > Next > tracking > Save. It ends with "review the summary, then press Publish yourself". Publish is never clicked. - Play content rating and target audience: Next by itself. Save draft, Submit, the final Save, Create and Create app stay the owner's. - An uncertain answer stops the walk on its page (outlined, "answer needed on ...") until the owner has set it; then it goes on. Fixture apple-app-privacy-flow.html (first time, ?existing=1, decoys); tests/console-flow.test.ts with the guardrail that no log line asks the owner to click a navigation control.
215 lines
14 KiB
TypeScript
215 lines
14 KiB
TypeScript
// storebound console fill walks a whole form: it clicks every navigation control (Next, App Privacy's Get Started,
|
|
// Edit next to Data Types, each data type) and App Privacy's in-dialog draft Save itself, stops only for an uncertain
|
|
// answer (until the owner set it), an agreement or the final button (Publish, Submit, Save, Create), which stays the
|
|
// owner's. Runs fillSession against MODELED pages (tests/fixtures/console) on 127.0.0.1. No network.
|
|
// Guardrail: no log line ever asks the owner to click a navigation control.
|
|
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
import { join } from 'node:path';
|
|
import { fillSession } from '../cli/console/fill';
|
|
import type { ConsoleBrowser } from '../cli/console/session';
|
|
import { APPLE_DATA_TYPE_IDS, type AppleDataTypeId, type AppleTypeAnswer } from '../cli/lib/app-privacy';
|
|
import type { ShipConfig } from '../cli/lib/config';
|
|
import { type FlowWhere, flowAllowed, flowClass, FORM_BUTTONS } from '../cli/lib/console-forms';
|
|
import { AFTER_ALL_MS, AFTER_EACH_MS, launchTestBrowser, logLines, testScope } from './helpers/browser';
|
|
|
|
const FIX = join(import.meta.dir, 'fixtures', 'console');
|
|
const base0: ShipConfig = {
|
|
app: { name: 'Example Game', profile: 'game', privacyPolicyUrl: 'https://example.com/privacy', supportUrl: 'https://example.com/support', website: 'https://example.com', contactEmail: 'support@example.com' },
|
|
languages: [{ id: 'en', play: 'en-US', apple: 'en-US' }],
|
|
apple: { bundleId: 'com.example.game', primaryLocale: 'en-US' },
|
|
play: { packageName: 'com.example.game' },
|
|
ads: { appAdsTxt: ['example-network.com, pub-0000, DIRECT, abc123'] },
|
|
dataSafety: { collectsData: true, encryptedInTransit: true, deletionRequest: false, data: { PSL_DEVICE_ID: { shared: true, collect: ['advertising', 'analytics'], share: ['advertising'] } } },
|
|
console: { contentRating: { answers: { violence: false } }, targetAudience: { ages: ['13-15', '16-17', '18-over'] } },
|
|
} as ShipConfig;
|
|
/** Every App Privacy answer certain: Device ID and Crash Data collected, nothing else. */
|
|
function privacy(over: Partial<Record<AppleDataTypeId, AppleTypeAnswer>> = {}): ShipConfig {
|
|
const types: Partial<Record<AppleDataTypeId, AppleTypeAnswer>> = Object.fromEntries(APPLE_DATA_TYPE_IDS.map(id => [id, { collected: false }]));
|
|
types.DEVICE_ID = { collected: true, purposes: ['THIRD_PARTY_ADVERTISING', 'ANALYTICS'], linked: false, tracking: true };
|
|
types.CRASH_DATA = { collected: true, purposes: ['APP_FUNCTIONALITY'], linked: false, tracking: false };
|
|
return { ...base0, dataSafety: undefined, appPrivacy: { types: { ...types, ...over } } } as unknown as ShipConfig;
|
|
}
|
|
|
|
const shared = await launchTestBrowser('playwright');
|
|
const { browser, skipWhy } = shared;
|
|
if (!browser) console.warn(`console-flow browser tests skipped: no Chromium installed (${skipWhy}). Run \`bunx playwright install chromium\`.`);
|
|
const scope = testScope(() => browser);
|
|
const TEST_MS = 60_000;
|
|
|
|
let server: ReturnType<typeof Bun.serve> | null = null;
|
|
let base = '';
|
|
beforeAll(() => {
|
|
server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch: req => {
|
|
const name = new URL(req.url).pathname.slice(1);
|
|
if (!/^[a-z_-]+\.(html|js)$/.test(name)) return new Response('not found', { status: 404 });
|
|
return new Response(Bun.file(join(FIX, name)));
|
|
} });
|
|
base = `http://127.0.0.1:${server.port}/`;
|
|
});
|
|
afterEach(() => scope.settle(), AFTER_EACH_MS);
|
|
afterAll(async () => { await shared.close(); server?.stop(true); }, AFTER_ALL_MS);
|
|
|
|
async function local(): Promise<ConsoleBrowser> {
|
|
const ctx = scope.track(await browser.newContext());
|
|
const page = await ctx.newPage();
|
|
let closed = false;
|
|
const done = new Promise<void>(r => ctx.on('close', () => { closed = true; r(); }));
|
|
return { mode: 'profile', context: ctx, page, pages: () => ctx.pages(), closed: done, isClosed: () => closed, close: () => ctx.close(), cleanup: () => {} };
|
|
}
|
|
const fast = (log: ReturnType<typeof logLines>) => ({ say: log.say, tickMs: 100, navTimeoutMs: 5000, signInWaitMs: 30_000, env: {} });
|
|
const clicks = (b: ConsoleBrowser): Promise<string[]> => b.page.evaluate(() => (window as any).__clicks);
|
|
const navClicks = (b: ConsoleBrowser): Promise<string[]> => b.page.evaluate(() => (window as any).__navClicks());
|
|
/** Guardrail: a line that tells the owner to click a navigation control themselves. */
|
|
const NAV_YOURSELF = /\b(Next|Continue|Get Started|Edit|Back|Set Up|Start|Manage|New App)\b[^.]*\byourself\b|\byourself\b[^.]*\b(Next|Continue|Get Started|Edit next|Set Up)\b/;
|
|
const navAsked = (lines: string[]) => lines.filter(l => NAV_YOURSELF.test(l));
|
|
const PUBLISH = 'review the summary, then press Publish yourself';
|
|
|
|
describe('button classes (FORM_BUTTONS, flowClass, flowAllowed)', () => {
|
|
const at = (w: Partial<FlowWhere> = {}): FlowWhere => ({ privacyPage: true, inDialog: false, inDataTypes: false, dataTypes: ['Device ID'], ...w });
|
|
test('App Privacy: openers, Next and the in-dialog Save are clicked; Publish never', () => {
|
|
expect(flowAllowed('apple-app-privacy', 'Get Started', 'button', at())).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Başlayın', 'button', at())).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Edit', 'button', at({ inDataTypes: true }))).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Edit', 'button', at())).toBe(false); // the Privacy Policy URL's Edit
|
|
expect(flowAllowed('apple-app-privacy', 'Set Up Device ID', 'button', at({ inDataTypes: true }))).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Device ID', 'link', at({ inDataTypes: true }))).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Next', 'button', at({ inDialog: true }))).toBe(true);
|
|
expect(flowClass('apple-app-privacy', 'Save', 'button', at({ inDialog: true }))).toBe('draft-save');
|
|
expect(flowAllowed('apple-app-privacy', 'Save', 'button', at({ inDialog: true }))).toBe(true);
|
|
expect(flowAllowed('apple-app-privacy', 'Save', 'button', at())).toBe(false); // not in a questionnaire dialog
|
|
expect(flowAllowed('apple-app-privacy', 'Save', 'button', at({ inDialog: true, privacyPage: false }))).toBe(false);
|
|
for (const n of ['Publish', 'Yayınla', 'Submit for Review']) expect(flowAllowed('apple-app-privacy', n, 'button', at({ inDialog: true, inDataTypes: true }))).toBe(false);
|
|
expect(flowAllowed('apple-app-privacy', 'Get Started', 'checkbox', at())).toBe(false);
|
|
});
|
|
test('other forms: Next is navigation; Save draft, Save, Submit, Create, Done stay the owner\'s', () => {
|
|
const w = at({ privacyPage: false });
|
|
for (const f of ['play-content-rating', 'play-target-audience', 'apple-app-record', 'play-app-record'] as const) {
|
|
expect(flowAllowed(f, 'Next', 'button', w)).toBe(true);
|
|
expect(flowAllowed(f, 'İleri', 'button', w)).toBe(true);
|
|
expect(flowAllowed(f, 'Get Started', 'button', w)).toBe(false);
|
|
for (const n of ['Save draft', 'Save', 'Submit', 'Create', 'Create app', 'Done', 'Start rollout', 'Publish']) expect(flowAllowed(f, n, 'button', w)).toBe(false);
|
|
}
|
|
expect(flowClass('play-content-rating', 'Save draft', 'button', w)).toBe('draft-save');
|
|
expect(flowClass('play-target-audience', 'Save', 'button', w)).toBe('final-submit');
|
|
expect(flowClass('play-content-rating', 'Submit', 'button', w)).toBe('final-submit');
|
|
});
|
|
test('every form has its buttons classified; only navigation and App Privacy\'s draft Save are automatic', () => {
|
|
for (const [f, rules] of Object.entries(FORM_BUTTONS)) {
|
|
expect(rules.length).toBeGreaterThan(0);
|
|
for (const r of rules) if (r.auto) expect(r.class === 'navigation' || (f === 'apple-app-privacy' && r.class === 'draft-save')).toBe(true);
|
|
expect(rules.some(r => r.class === 'final-submit' && !r.auto)).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe.skipIf(!browser)('App Privacy: the whole questionnaire (fixture apple-app-privacy-flow.html)', () => {
|
|
test('first time: Get Started > yes > Next > data types > Save > each type (purposes > Next > linked > Next > tracking > Save); Publish never clicked', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const run = scope.run(fillSession(b, { form: 'apple-app-privacy', config: privacy(), startUrl: base + 'apple-app-privacy-flow.html', ...fast(log) }));
|
|
await log.wait('the Publish line', l => l.some(m => m.startsWith(PUBLISH)));
|
|
const c = await clicks(b);
|
|
expect(c).not.toContain('Publish');
|
|
expect(c).not.toContain('See Details');
|
|
expect(c).not.toContain('Edit'); // neither the Privacy Policy Edit nor (first time) the Data Types one
|
|
expect(c.filter(x => x === 'Get Started')).toHaveLength(1);
|
|
expect(await b.page.evaluate(() => (window as any).__saves)).toBe(3); // the type list + Device ID + Crash Data, drafts
|
|
expect(await navClicks(b)).toContain('Crash Data'); // the link of the second type
|
|
expect(c).toContain('Set Up Device ID');
|
|
expect(log.lines).toContain('clicked "Save" (draft-save)');
|
|
expect(log.lines.some(m => m.startsWith('answer needed'))).toBe(false);
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
expect((await run).fallback).toBe(false);
|
|
}, TEST_MS);
|
|
|
|
test('answers exist: Edit next to Data Types (never the Privacy Policy Edit), then every type', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const run = scope.run(fillSession(b, { form: 'apple-app-privacy', config: privacy(), startUrl: base + 'apple-app-privacy-flow.html?existing=1', ...fast(log) }));
|
|
await log.wait('the Publish line', l => l.some(m => m.startsWith(PUBLISH)));
|
|
expect((await clicks(b)).filter(x => x === 'Edit')).toHaveLength(1);
|
|
expect(log.lines.some(m => m.startsWith('Data collection was answered before'))).toBe(true);
|
|
expect(await b.page.evaluate(() => (window as any).__saves)).toBe(3);
|
|
expect(await clicks(b)).not.toContain('Publish');
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
await run;
|
|
}, TEST_MS);
|
|
|
|
test('an uncertain answer stops the walk on its page until the owner sets it, then it goes on', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const config = privacy({ DEVICE_ID: { collected: true, purposes: ['ANALYTICS'], tracking: false } }); // linked: not in the config
|
|
const run = scope.run(fillSession(b, { form: 'apple-app-privacy', config, startUrl: base + 'apple-app-privacy-flow.html', ...fast(log) }));
|
|
await log.wait('the stop', l => l.some(m => m.startsWith('answer needed on "Device ID: linked to the user"')));
|
|
await Bun.sleep(600); // several rounds: Next must not be clicked past the open question
|
|
const linked = b.page.getByRole('radio', { name: /^No, Device ID .* not linked/ });
|
|
expect(await linked.isVisible()).toBe(true);
|
|
expect(await b.page.getByRole('radio', { name: /^No, we do not use Device ID/ }).isVisible()).toBe(false);
|
|
await linked.check(); // the owner answers
|
|
await log.wait('the Publish line', l => l.some(m => m.startsWith(PUBLISH)));
|
|
expect(log.lines).toContain('"Device ID: linked to the user" answered: storebound goes on');
|
|
expect(await b.page.evaluate(() => (window as any).__saves)).toBe(3);
|
|
expect(await clicks(b)).not.toContain('Publish');
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
await run;
|
|
}, TEST_MS);
|
|
|
|
test('no data collected: "No" and the dialog\'s Save, then the summary', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const types = Object.fromEntries(APPLE_DATA_TYPE_IDS.map(id => [id, { collected: false }]));
|
|
const config = { ...base0, dataSafety: undefined, appPrivacy: { types } } as unknown as ShipConfig;
|
|
const run = scope.run(fillSession(b, { form: 'apple-app-privacy', config, startUrl: base + 'apple-app-privacy-flow.html', ...fast(log) }));
|
|
await log.wait('the Publish line', l => l.some(m => m.startsWith(PUBLISH)));
|
|
expect(await b.page.evaluate(() => (window as any).__saves)).toBe(1);
|
|
expect(await clicks(b)).not.toContain('Next');
|
|
expect(await clicks(b)).not.toContain('Publish');
|
|
await b.context.close();
|
|
await run;
|
|
}, TEST_MS);
|
|
});
|
|
|
|
describe.skipIf(!browser)('the other forms: navigation by itself, final buttons and draft saves left to the owner', () => {
|
|
test('content rating: Next after the category by itself; stops at the uncertain questions; Save draft / Submit never clicked', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const run = scope.run(fillSession(b, { form: 'play-content-rating', config: base0, startUrl: base + 'play-content-rating.html', ...fast(log) }));
|
|
await log.wait('the questionnaire stop', l => l.some(m => m.startsWith('answer needed on "Questionnaire"')));
|
|
expect(log.lines).toContain('clicked "Next" (navigation)');
|
|
const c = await clicks(b);
|
|
expect(c).toEqual(['Next']);
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
await run;
|
|
}, TEST_MS);
|
|
|
|
test('target audience: Next by itself, a stop at the uncertain appeal question until answered, then Next; Save stays the owner\'s', async () => {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const run = scope.run(fillSession(b, { form: 'play-target-audience', config: base0, startUrl: base + 'play-target-audience.html', ...fast(log) }));
|
|
await log.wait('the appeal stop', l => l.some(m => m.startsWith('answer needed on "Appeal to children"')));
|
|
expect(await clicks(b)).toEqual(['Next']);
|
|
await b.page.getByRole('radiogroup', { name: /appeal to children/ }).getByRole('radio', { name: 'No' }).check();
|
|
await log.wait('the final line', l => l.some(m => m.includes('press Save yourself')));
|
|
expect(await clicks(b)).toEqual(['Next', 'Next']);
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
await run;
|
|
}, TEST_MS);
|
|
|
|
test('New App (App Store) and Create app (Play): filled, the final button is the owner\'s, no navigation asked of the owner', async () => {
|
|
for (const [form, file, final] of [['apple-app-record', 'apple-app-record.html', 'Create'], ['play-app-record', 'play-create-app.html', 'Create app']] as const) {
|
|
const b = await local();
|
|
const log = logLines();
|
|
const run = scope.run(fillSession(b, { form, config: base0, startUrl: base + file, ...fast(log) }));
|
|
await log.wait('the final line', l => l.some(m => m.includes(`press ${final} yourself`)));
|
|
expect(await clicks(b)).toEqual([]);
|
|
expect(navAsked(log.lines)).toEqual([]);
|
|
await b.context.close();
|
|
await run;
|
|
}
|
|
}, TEST_MS);
|
|
});
|