@symbiosis-lab/moss-plugin-github 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +18 -0
- package/assets/icon.svg +3 -0
- package/assets/manifest.json +19 -0
- package/e2e/deploy-api.test.ts +1129 -0
- package/e2e/moss-cli.test.ts +478 -0
- package/features/auth/device-flow.feature +41 -0
- package/features/deploy/validation.feature +50 -0
- package/features/steps/auth.steps.ts +285 -0
- package/features/steps/deploy.steps.ts +354 -0
- package/package.json +51 -0
- package/src/__tests__/auth-flow.integration.test.ts +738 -0
- package/src/__tests__/auth.test.ts +147 -0
- package/src/__tests__/configure-domain.test.ts +263 -0
- package/src/__tests__/deploy.integration.test.ts +798 -0
- package/src/__tests__/git.test.ts +190 -0
- package/src/__tests__/github-api.test.ts +761 -0
- package/src/__tests__/github-deploy.test.ts +2411 -0
- package/src/__tests__/progress-timeout.test.ts +209 -0
- package/src/__tests__/repo-setup-progress.test.ts +367 -0
- package/src/__tests__/repo-setup.test.ts +370 -0
- package/src/__tests__/token.test.ts +152 -0
- package/src/__tests__/utils.test.ts +129 -0
- package/src/__tests__/workflow.test.ts +146 -0
- package/src/auth.ts +588 -0
- package/src/constants.ts +7 -0
- package/src/git.ts +60 -0
- package/src/github-api.ts +601 -0
- package/src/github-deploy.ts +593 -0
- package/src/main.ts +646 -0
- package/src/repo-setup.ts +685 -0
- package/src/token.ts +202 -0
- package/src/types.ts +91 -0
- package/src/utils.ts +108 -0
- package/src/workflow.ts +79 -0
- package/test-helpers/mock-github-api.ts +217 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +50 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit and integration tests for workflow.ts
|
|
3
|
+
*
|
|
4
|
+
* Pure functions are tested directly.
|
|
5
|
+
* Tauri-dependent functions are tested with mock context.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
9
|
+
import {
|
|
10
|
+
setupMockTauri,
|
|
11
|
+
type MockTauriContext,
|
|
12
|
+
} from "@symbiosis-lab/moss-api/testing";
|
|
13
|
+
|
|
14
|
+
// workflow.ts no longer imports from utils — no mock needed
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
WORKFLOW_TEMPLATE,
|
|
18
|
+
generateWorkflowContent,
|
|
19
|
+
createWorkflowFile,
|
|
20
|
+
workflowExists,
|
|
21
|
+
} from "../workflow";
|
|
22
|
+
|
|
23
|
+
describe("WORKFLOW_TEMPLATE", () => {
|
|
24
|
+
it("contains the branch placeholder", () => {
|
|
25
|
+
expect(WORKFLOW_TEMPLATE).toContain("BRANCH_PLACEHOLDER");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("includes required GitHub Actions setup", () => {
|
|
29
|
+
expect(WORKFLOW_TEMPLATE).toContain("actions/checkout@v4");
|
|
30
|
+
expect(WORKFLOW_TEMPLATE).toContain("actions/configure-pages@v4");
|
|
31
|
+
expect(WORKFLOW_TEMPLATE).toContain("actions/upload-pages-artifact@v3");
|
|
32
|
+
expect(WORKFLOW_TEMPLATE).toContain("actions/deploy-pages@v4");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("includes correct permissions", () => {
|
|
36
|
+
expect(WORKFLOW_TEMPLATE).toContain("contents: read");
|
|
37
|
+
expect(WORKFLOW_TEMPLATE).toContain("pages: write");
|
|
38
|
+
expect(WORKFLOW_TEMPLATE).toContain("id-token: write");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("references .moss/build/current as the upload path (current generation symlink)", () => {
|
|
42
|
+
expect(WORKFLOW_TEMPLATE).toContain("path: .moss/build/current");
|
|
43
|
+
// Must NOT reference the now-empty legacy .moss/build/site path
|
|
44
|
+
expect(WORKFLOW_TEMPLATE).not.toContain("path: .moss/build/site");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("includes workflow_dispatch trigger", () => {
|
|
48
|
+
expect(WORKFLOW_TEMPLATE).toContain("workflow_dispatch:");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("generateWorkflowContent", () => {
|
|
53
|
+
it("replaces placeholder with main branch", () => {
|
|
54
|
+
const result = generateWorkflowContent("main");
|
|
55
|
+
expect(result).toContain("branches: [main]");
|
|
56
|
+
expect(result).not.toContain("BRANCH_PLACEHOLDER");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("replaces placeholder with master branch", () => {
|
|
60
|
+
const result = generateWorkflowContent("master");
|
|
61
|
+
expect(result).toContain("branches: [master]");
|
|
62
|
+
expect(result).not.toContain("BRANCH_PLACEHOLDER");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("replaces placeholder with custom branch", () => {
|
|
66
|
+
const result = generateWorkflowContent("develop");
|
|
67
|
+
expect(result).toContain("branches: [develop]");
|
|
68
|
+
expect(result).not.toContain("BRANCH_PLACEHOLDER");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("generates valid YAML structure", () => {
|
|
72
|
+
const result = generateWorkflowContent("main");
|
|
73
|
+
|
|
74
|
+
// Check for valid YAML key structure
|
|
75
|
+
expect(result).toContain("name: Deploy to GitHub Pages");
|
|
76
|
+
expect(result).toContain("on:");
|
|
77
|
+
expect(result).toContain("permissions:");
|
|
78
|
+
expect(result).toContain("jobs:");
|
|
79
|
+
expect(result).toContain("deploy:");
|
|
80
|
+
expect(result).toContain("steps:");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("preserves the moss header comment", () => {
|
|
84
|
+
const result = generateWorkflowContent("main");
|
|
85
|
+
expect(result).toContain("# moss GitHub Pages Deployment");
|
|
86
|
+
expect(result).toContain("Generated by moss");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// ============================================================================
|
|
91
|
+
// Integration tests for Tauri-dependent functions
|
|
92
|
+
// ============================================================================
|
|
93
|
+
|
|
94
|
+
describe("createWorkflowFile", () => {
|
|
95
|
+
let ctx: MockTauriContext;
|
|
96
|
+
const projectPath = "/test/project";
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
ctx = setupMockTauri({ projectPath });
|
|
100
|
+
vi.clearAllMocks();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
ctx.cleanup();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("creates workflow file with correct content", async () => {
|
|
108
|
+
await createWorkflowFile("main");
|
|
109
|
+
|
|
110
|
+
const file = ctx.filesystem.getFile(`${projectPath}/.github/workflows/moss-deploy.yml`);
|
|
111
|
+
expect(file?.content).toContain("branches: [main]");
|
|
112
|
+
expect(file?.content).toContain("Deploy to GitHub Pages");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("uses custom branch name in workflow", async () => {
|
|
116
|
+
await createWorkflowFile("develop");
|
|
117
|
+
|
|
118
|
+
const file = ctx.filesystem.getFile(`${projectPath}/.github/workflows/moss-deploy.yml`);
|
|
119
|
+
expect(file?.content).toContain("branches: [develop]");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("workflowExists", () => {
|
|
124
|
+
let ctx: MockTauriContext;
|
|
125
|
+
const projectPath = "/test/project";
|
|
126
|
+
|
|
127
|
+
beforeEach(() => {
|
|
128
|
+
ctx = setupMockTauri({ projectPath });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
afterEach(() => {
|
|
132
|
+
ctx.cleanup();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("returns true when workflow file exists", async () => {
|
|
136
|
+
ctx.filesystem.setFile(`${projectPath}/.github/workflows/moss-deploy.yml`, "name: Test");
|
|
137
|
+
|
|
138
|
+
const result = await workflowExists();
|
|
139
|
+
expect(result).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("returns false when workflow file does not exist", async () => {
|
|
143
|
+
const result = await workflowExists();
|
|
144
|
+
expect(result).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
});
|