@walker-di/fortalece-ai-sdk 0.3.8 → 0.3.10
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-preview-comment.test.d.ts","sourceRoot":"","sources":["../../../src/ci/__tests__/github-preview-comment.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { upsertPreviewDeploymentComment } from '../github-preview-comment.js';
|
|
3
|
+
function createGitHubMock(existingComments = []) {
|
|
4
|
+
const comments = [...existingComments];
|
|
5
|
+
const createComment = vi.fn(async ({ body }) => {
|
|
6
|
+
const created = {
|
|
7
|
+
id: comments.length + 1,
|
|
8
|
+
body,
|
|
9
|
+
user: { type: 'Bot' },
|
|
10
|
+
};
|
|
11
|
+
comments.push(created);
|
|
12
|
+
return { data: created };
|
|
13
|
+
});
|
|
14
|
+
const updateComment = vi.fn(async ({ comment_id, body }) => {
|
|
15
|
+
const index = comments.findIndex((comment) => comment.id === comment_id);
|
|
16
|
+
if (index >= 0) {
|
|
17
|
+
comments[index] = {
|
|
18
|
+
...comments[index],
|
|
19
|
+
body,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { data: comments[index] };
|
|
23
|
+
});
|
|
24
|
+
const github = {
|
|
25
|
+
paginate: vi.fn(async () => comments),
|
|
26
|
+
rest: {
|
|
27
|
+
issues: {
|
|
28
|
+
listComments: vi.fn(),
|
|
29
|
+
createComment,
|
|
30
|
+
updateComment,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
github,
|
|
36
|
+
comments,
|
|
37
|
+
createComment,
|
|
38
|
+
updateComment,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const context = {
|
|
42
|
+
repo: {
|
|
43
|
+
owner: 'walker',
|
|
44
|
+
repo: 'pic-pay',
|
|
45
|
+
},
|
|
46
|
+
issue: {
|
|
47
|
+
number: 305,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
function createBaseEnv(overrides = {}) {
|
|
51
|
+
return {
|
|
52
|
+
PR_NUMBER: '305',
|
|
53
|
+
PROJECT_ID: 'fortalece-ai-web',
|
|
54
|
+
REGION: 'us-east1',
|
|
55
|
+
SERVICE_NAME: 'fortalece-ai-pr305',
|
|
56
|
+
COMMIT_SHA: 'bdb34e0123456789',
|
|
57
|
+
BRANCH: 'feat/thread-action',
|
|
58
|
+
RUN_URL: 'https://github.com/walker/pic-pay/actions/runs/123',
|
|
59
|
+
BUILD_ID: 'build-123',
|
|
60
|
+
PROJECT_LABEL: 'fortalece-ai',
|
|
61
|
+
COMMENT_KEY: 'preview-deployment-fortalece-ai',
|
|
62
|
+
LEGACY_MATCHERS: 'Fortalece AI Preview',
|
|
63
|
+
PREVIEW_URL: 'https://fortalece-ai-pr305-ss67iehpea-ue.a.run.app',
|
|
64
|
+
...overrides,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
describe('github preview comment core', () => {
|
|
68
|
+
it('creates a Preview Deployment building comment with marker', async () => {
|
|
69
|
+
const { github, createComment, comments } = createGitHubMock();
|
|
70
|
+
const core = { info: vi.fn() };
|
|
71
|
+
await upsertPreviewDeploymentComment({
|
|
72
|
+
github,
|
|
73
|
+
context,
|
|
74
|
+
core,
|
|
75
|
+
status: 'building',
|
|
76
|
+
env: createBaseEnv(),
|
|
77
|
+
});
|
|
78
|
+
expect(createComment).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(comments).toHaveLength(1);
|
|
80
|
+
const body = comments[0]?.body || '';
|
|
81
|
+
expect(body).toContain('## 🚀 Preview Deployment');
|
|
82
|
+
expect(body).toContain('| Project | Deployment | Preview | Logs | Updated (UTC) |');
|
|
83
|
+
expect(body).toContain('| **fortalece-ai** | 🟡 Building |');
|
|
84
|
+
expect(body).toContain('<!-- fortalece-preview-comment:preview-deployment-fortalece-ai -->');
|
|
85
|
+
});
|
|
86
|
+
it('updates existing comment when marker matches', async () => {
|
|
87
|
+
const existingCommentBody = `## 🚀 Preview Deployment
|
|
88
|
+
| Project | Deployment | Preview | Logs | Updated (UTC) |
|
|
89
|
+
|---------|------------|---------|------|---------------|
|
|
90
|
+
| **fortalece-ai** | 🟡 Building | [View Build](https://example.com/build) | - | Sat, 07 Feb 2026 10:00:00 GMT |
|
|
91
|
+
<!-- fortalece-preview-comment:preview-deployment-fortalece-ai -->`;
|
|
92
|
+
const { github, createComment, updateComment, comments } = createGitHubMock([
|
|
93
|
+
{ id: 99, body: existingCommentBody, user: { type: 'Bot' } },
|
|
94
|
+
]);
|
|
95
|
+
const core = { info: vi.fn() };
|
|
96
|
+
await upsertPreviewDeploymentComment({
|
|
97
|
+
github,
|
|
98
|
+
context,
|
|
99
|
+
core,
|
|
100
|
+
status: 'success',
|
|
101
|
+
env: createBaseEnv(),
|
|
102
|
+
});
|
|
103
|
+
expect(createComment).not.toHaveBeenCalled();
|
|
104
|
+
expect(updateComment).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(updateComment).toHaveBeenCalledWith(expect.objectContaining({
|
|
106
|
+
comment_id: 99,
|
|
107
|
+
}));
|
|
108
|
+
expect(comments[0]?.body).toContain('| **fortalece-ai** | 🟢 Ready |');
|
|
109
|
+
});
|
|
110
|
+
it('upgrades legacy Fortalece comment on first run', async () => {
|
|
111
|
+
const { github, createComment, updateComment, comments } = createGitHubMock([
|
|
112
|
+
{
|
|
113
|
+
id: 7,
|
|
114
|
+
body: `## 🚀 Fortalece AI Preview Ready!
|
|
115
|
+
| Field | Value |
|
|
116
|
+
|-------|-------|
|
|
117
|
+
| **Preview URL** | https://old.run.app |`,
|
|
118
|
+
user: { type: 'Bot' },
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
const core = { info: vi.fn() };
|
|
122
|
+
await upsertPreviewDeploymentComment({
|
|
123
|
+
github,
|
|
124
|
+
context,
|
|
125
|
+
core,
|
|
126
|
+
status: 'success',
|
|
127
|
+
env: createBaseEnv(),
|
|
128
|
+
});
|
|
129
|
+
expect(createComment).not.toHaveBeenCalled();
|
|
130
|
+
expect(updateComment).toHaveBeenCalledTimes(1);
|
|
131
|
+
expect(comments[0]?.body).toContain('## 🚀 Preview Deployment');
|
|
132
|
+
expect(comments[0]?.body).toContain('<!-- fortalece-preview-comment:preview-deployment-fortalece-ai -->');
|
|
133
|
+
});
|
|
134
|
+
it('keeps project comments separate by COMMENT_KEY', async () => {
|
|
135
|
+
const { github, createComment, updateComment } = createGitHubMock([
|
|
136
|
+
{
|
|
137
|
+
id: 41,
|
|
138
|
+
body: `## 🚀 Preview Deployment
|
|
139
|
+
| Project | Deployment | Preview | Logs | Updated (UTC) |
|
|
140
|
+
|---------|------------|---------|------|---------------|
|
|
141
|
+
| **pic-flow** | 🟢 Ready | [Visit Preview](https://pic-flow.run.app) | [View Logs](https://example.com/logs) | Sat, 07 Feb 2026 10:00:00 GMT |
|
|
142
|
+
<!-- fortalece-preview-comment:preview-deployment-pic-flow -->`,
|
|
143
|
+
user: { type: 'Bot' },
|
|
144
|
+
},
|
|
145
|
+
]);
|
|
146
|
+
const core = { info: vi.fn() };
|
|
147
|
+
await upsertPreviewDeploymentComment({
|
|
148
|
+
github,
|
|
149
|
+
context,
|
|
150
|
+
core,
|
|
151
|
+
status: 'building',
|
|
152
|
+
env: createBaseEnv(),
|
|
153
|
+
});
|
|
154
|
+
expect(updateComment).not.toHaveBeenCalled();
|
|
155
|
+
expect(createComment).toHaveBeenCalledTimes(1);
|
|
156
|
+
const createdBody = createComment.mock.calls[0]?.[0]?.body || '';
|
|
157
|
+
expect(createdBody).toContain('**fortalece-ai**');
|
|
158
|
+
expect(createdBody).toContain('<!-- fortalece-preview-comment:preview-deployment-fortalece-ai -->');
|
|
159
|
+
});
|
|
160
|
+
});
|