Skip to content

Commit b6da5b6

Browse files
committed
feat(web): add test server utilities and configuration files
- Introduced `test-server.ts` for creating isolated test environments for API integration testing. - Added `tsconfig.json` for TypeScript configuration specific to the web package. - Created `vercel.json` for production environment variables. - Implemented `vitest.config.ts` for testing setup and configuration. - Updated `pnpm-lock.yaml` to include dependencies for the web package. - Modified `pnpm-workspace.yaml` to remove the apps directory from workspace packages. - Adjusted validation scripts to reference the new packages/web directory structure.
1 parent a897989 commit b6da5b6

File tree

249 files changed

+1425
-1363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+1425
-1363
lines changed

.github/scripts/README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,103 @@ This directory contains reusable shell scripts to optimize and simplify GitHub A
1515
### Core Build & Test Scripts
1616

1717
#### `setup-node.sh`
18+
1819
Sets up Node.js environment and installs dependencies with pnpm.
20+
1921
```bash
2022
./.github/scripts/setup-node.sh [node_version] [pnpm_version]
2123
```
24+
2225
- **Default**: Node.js 20, pnpm 10.15.0
2326
- **Used in**: All workflows that need Node.js
2427

2528
#### `build-packages.sh`
29+
2630
Builds all packages in dependency order (core → ai → mcp → web).
31+
2732
```bash
2833
./.github/scripts/build-packages.sh
2934
```
35+
3036
- **Dependencies**: Requires pnpm workspace setup
31-
- **Output**: Build artifacts in `packages/*/build` and `apps/web/.next-build`
37+
- **Output**: Build artifacts in `packages/*/build` and `packages/web/.next-build`
3238

3339
#### `verify-build.sh`
40+
3441
Verifies that all expected build artifacts exist.
42+
3543
```bash
3644
./.github/scripts/verify-build.sh
3745
```
38-
- **Checks**:
46+
47+
- **Checks**:
3948
- Core, AI, MCP, CLI packages: `build/index.js` and `build/index.d.ts`
4049
- Web package: `.next-build/` directory
4150
- **Exit codes**: 0 = success, 1 = missing artifacts
4251

4352
#### `run-tests.sh`
53+
4454
Runs tests for all packages with coverage.
55+
4556
```bash
4657
./.github/scripts/run-tests.sh
4758
```
59+
4860
- **Command**: `pnpm -r test:coverage`
4961
- **Requirements**: All packages must have `test:coverage` script
5062

5163
### NPM Publishing Scripts
5264

5365
#### `check-versions.sh`
66+
5467
Determines which packages need to be published based on version comparison.
68+
5569
```bash
5670
./.github/scripts/check-versions.sh [force_publish] [package_filter]
5771
```
72+
5873
- **Parameters**:
5974
- `force_publish`: "true" to force publish regardless of versions
6075
- `package_filter`: Comma-separated list (e.g., "core,mcp")
6176
- **Output**: Sets GitHub Actions outputs for downstream jobs
6277
- **Environment**: Requires `NODE_AUTH_TOKEN` for NPM registry access
6378

6479
#### `publish-packages.sh`
80+
6581
Publishes specified packages to NPM registry.
82+
6683
```bash
6784
./.github/scripts/publish-packages.sh "mcp,core,ai"
6885
```
86+
6987
- **Input**: Comma-separated package list
7088
- **Environment**: Requires `NODE_AUTH_TOKEN`
7189
- **Output**: Sets `published_packages` GitHub Actions output
7290

7391
### Docker & Validation Scripts
7492

7593
#### `test-docker.sh`
94+
7695
Tests Docker image functionality by starting container and checking endpoints.
96+
7797
```bash
7898
./.github/scripts/test-docker.sh "image:tag"
7999
```
100+
80101
- **Tests**:
81102
- Container starts successfully
82103
- HTTP endpoint responds (port 3000)
83104
- Health check endpoint (if available)
84105
- **Cleanup**: Automatically stops test container
85106

86107
#### `validate-pr.sh`
108+
87109
Runs lightweight validation checks for pull requests.
110+
88111
```bash
89112
./.github/scripts/validate-pr.sh
90113
```
114+
91115
- **Checks**:
92116
- TypeScript compilation
93117
- Quick build test (core, ai, mcp packages)
@@ -97,6 +121,7 @@ Runs lightweight validation checks for pull requests.
97121
## 🔧 Usage in Workflows
98122

99123
### Before (Workflow with inline scripts)
124+
100125
```yaml
101126
- name: Build packages
102127
run: |
@@ -107,6 +132,7 @@ Runs lightweight validation checks for pull requests.
107132
```
108133
109134
### After (Workflow with script)
135+
110136
```yaml
111137
- name: Build packages
112138
run: ./.github/scripts/build-packages.sh
@@ -132,48 +158,55 @@ All scripts can be tested locally:
132158
## 🔍 Script Standards
133159

134160
### Error Handling
161+
135162
- All scripts use `set -euo pipefail` for strict error handling
136163
- Exit codes: 0 = success, 1 = failure
137164
- Clear error messages with emojis for visibility
138165

139166
### GitHub Actions Integration
167+
140168
- Scripts write to `$GITHUB_OUTPUT` when available
141169
- Fallback to stdout for local testing
142170
- Support both CI and local environments
143171

144172
### Logging
173+
145174
- Consistent emoji prefixes for different operations:
146175
- 🔧 Setup/configuration
147176
- 🔨 Building
148-
- 🧪 Testing
177+
- 🧪 Testing
149178
- 📦 Packaging/publishing
150179
- 🐳 Docker operations
151180
- ✅ Success
152181
- ❌ Failure
153182
- ⚠️ Warning
154183

155184
### Parameters
185+
156186
- Support both required and optional parameters
157187
- Provide sensible defaults
158188
- Document parameter usage in script comments
159189

160190
## 📊 Performance Impact
161191

162192
### Before Refactoring
193+
163194
- **Duplicated logic**: ~150 lines across 3 workflows
164195
- **Maintenance**: Changes needed in multiple files
165196
- **Testing**: Difficult to test workflow logic locally
166197

167-
### After Refactoring
198+
### After Refactoring
199+
168200
- **Centralized logic**: ~50 lines per workflow (70% reduction)
169201
- **Maintenance**: Changes in single script files
170202
- **Testing**: Scripts testable locally and in CI
171203

172204
## 🚀 Future Enhancements
173205

174206
Potential improvements:
207+
175208
- **Script parameters**: More configurable options
176209
- **Parallel execution**: Where safe and beneficial
177-
- **Advanced caching**: More granular cache strategies
210+
- **Advanced caching**: More granular cache strategies
178211
- **Integration testing**: End-to-end workflow testing
179212
- **Monitoring**: Script execution metrics

.github/scripts/verify-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else
3131
fi
3232

3333
# Check web package
34-
if [ -d "apps/web/.next" ]; then
34+
if [ -d "packages/web/.next" ]; then
3535
echo "✅ Web package build artifacts verified"
3636
else
3737
echo "❌ Web package build artifacts missing"

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
with:
7878
path: |
7979
packages/*/build
80-
apps/web/.next-build
80+
packages/web/.next-build
8181
key: build-${{ github.sha }}-${{ matrix.node-version }}
8282

8383
- name: Verify build artifacts
@@ -191,7 +191,7 @@ jobs:
191191
with:
192192
path: |
193193
packages/*/build
194-
apps/web/.next-build
194+
packages/web/.next-build
195195
key: build-${{ github.sha }}-20
196196

197197
- name: Check versions and determine what to publish
@@ -275,7 +275,7 @@ jobs:
275275
with:
276276
path: |
277277
packages/*/build
278-
apps/web/.next-build
278+
packages/web/.next-build
279279
key: build-${{ github.sha }}-20
280280

281281
- name: Bump to dev prerelease versions

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ FROM base AS deps
2525
# Copy package.json files for proper dependency resolution
2626
COPY packages/core/package.json ./packages/core/
2727
COPY packages/ai/package.json ./packages/ai/
28-
COPY apps/web/package.json ./apps/web/
28+
COPY packages/web/package.json ./packages/web/
2929

3030
# Install dependencies
3131
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
@@ -39,12 +39,12 @@ FROM base AS builder
3939
COPY --from=deps /app/node_modules ./node_modules
4040
COPY --from=deps /app/packages/core/node_modules ./packages/core/node_modules
4141
COPY --from=deps /app/packages/ai/node_modules ./packages/ai/node_modules
42-
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
42+
COPY --from=deps /app/packages/web/node_modules ./packages/web/node_modules
4343

4444
# Copy source code (excluding MCP package)
4545
COPY packages/core ./packages/core
4646
COPY packages/ai ./packages/ai
47-
COPY apps/web ./apps/web
47+
COPY packages/web ./packages/web
4848
COPY tsconfig.json ./
4949
COPY vitest.config.base.ts ./
5050

@@ -75,12 +75,12 @@ RUN addgroup --system --gid 1001 nodejs
7575
RUN adduser --system --uid 1001 nextjs
7676

7777
# Copy the standalone build output and static files
78-
COPY --from=builder /app/apps/web/.next-build/standalone ./
79-
COPY --from=builder /app/apps/web/.next-build/static ./apps/web/.next-build/static
80-
COPY --from=builder /app/apps/web/public ./apps/web/public
78+
COPY --from=builder /app/packages/web/.next-build/standalone ./
79+
COPY --from=builder /app/packages/web/.next-build/static ./packages/web/.next-build/static
80+
COPY --from=builder /app/packages/web/public ./packages/web/public
8181

8282
# Create directories that the application might need and set permissions
83-
RUN mkdir -p /app/apps/web/.devlog /app/.devlog && \
83+
RUN mkdir -p /app/packages/web/.devlog /app/.devlog && \
8484
chown -R nextjs:nodejs /app
8585

8686
# Set correct permissions
@@ -93,4 +93,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
9393
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
9494

9595
# Start the Next.js application using the standalone server
96-
CMD ["node", "apps/web/server.js"]
96+
CMD ["node", "packages/web/server.js"]

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
1818
# Copy package files for web application dependencies only
1919
COPY packages/ai/package.json ./packages/ai/
2020
COPY packages/core/package.json ./packages/core/
21-
COPY apps/web/package.json ./apps/web/
21+
COPY packages/web/package.json ./packages/web/
2222

2323
# Install dependencies
2424
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install

0 commit comments

Comments
 (0)