Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/fleet/src/__tests__/configure-init-spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,50 @@ describe('InitInputSchema (Contract Tests)', () => {
});
expect(result.success).toBe(false);
});

// ── Auth mode contract tests ──────────────────────────────

it('accepts auth=app', () => {
const result = InitInputSchema.safeParse({
owner: 'google',
repoName: 'sdk',
auth: 'app',
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.auth).toBe('app');
}
});

it('accepts auth=token', () => {
const result = InitInputSchema.safeParse({
owner: 'google',
repoName: 'sdk',
auth: 'token',
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.auth).toBe('token');
}
});

it('defaults auth to token when omitted', () => {
const result = InitInputSchema.safeParse({
owner: 'google',
repoName: 'sdk',
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.auth).toBe('token');
}
});

it('rejects unknown auth modes', () => {
const result = InitInputSchema.safeParse({
owner: 'google',
repoName: 'sdk',
auth: 'oauth',
});
expect(result.success).toBe(false);
});
});
6 changes: 5 additions & 1 deletion packages/fleet/src/__tests__/label-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ describe('FLEET_LABEL_TEMPLATE', () => {

expect(content).toContain('name: Fleet Label PR');
expect(content).toContain('pull_request:');
expect(content).toContain('types: [opened]');
expect(content).toContain('runs-on: ubuntu-latest');
expect(content).toContain('gh pr edit');
expect(content).toContain('fleet-merge-ready');
expect(content).toContain('gh issue view "$ISSUE_NUMBER"');
});

it('triggers on opened, edited, and synchronize', () => {
const content = FLEET_LABEL_TEMPLATE.content;
expect(content).toContain('types: [opened, edited, synchronize]');
});
});
3 changes: 2 additions & 1 deletion packages/fleet/src/cli/init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default defineCommand({

// ── Dry run: list files and exit ──
if (dryRun) {
const files = buildWorkflowTemplates(intervalMinutes).map((t) => t.repoPath);
const files = buildWorkflowTemplates(intervalMinutes, wizardResult.authMethod).map((t) => t.repoPath);
files.push('.fleet/goals/example.md');
emit({ type: 'init:dry-run', files });
renderer.end(`Dry run complete. ${files.length} files would be created.`);
Expand All @@ -142,6 +142,7 @@ export default defineCommand({
overwrite,
features,
intervalMinutes,
auth: wizardResult.authMethod,
});

const octokit = createFleetOctokit();
Expand Down
2 changes: 1 addition & 1 deletion packages/fleet/src/init/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class InitHandler implements InitSpec {
};

// 2. Resolve which templates to commit
let templates = buildWorkflowTemplates(input.intervalMinutes);
let templates = buildWorkflowTemplates(input.intervalMinutes, input.auth);
if (input.features) {
const reconciler = new FeatureReconcileHandler(this.octokit);
const featureResult = await reconciler.execute({
Expand Down
7 changes: 7 additions & 0 deletions packages/fleet/src/init/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import { z } from 'zod';

// ── AUTH MODE ───────────────────────────────────────────────────────

export const AuthModeSchema = z.enum(['token', 'app']).default('token');
export type AuthMode = z.infer<typeof AuthModeSchema>;

// ── INPUT ───────────────────────────────────────────────────────────

export const InitInputSchema = z.object({
Expand All @@ -34,6 +39,8 @@ export const InitInputSchema = z.object({
features: z.record(z.string(), z.boolean()).optional(),
/** Pipeline cadence in minutes (min 5 per GitHub Actions, default 360 = 6h) */
intervalMinutes: z.number().min(5).default(360),
/** Auth mode: 'token' uses secrets.GITHUB_TOKEN, 'app' generates a GitHub App token */
auth: AuthModeSchema,
});

export type InitInput = z.infer<typeof InitInputSchema>;
Expand Down
2 changes: 1 addition & 1 deletion packages/fleet/src/init/templates/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const FLEET_LABEL_TEMPLATE: WorkflowTemplate = {
content: `name: Fleet Label PR
on:
pull_request:
types: [opened]
types: [opened, edited, synchronize]

permissions:
pull-requests: write
Expand Down
Loading