Skip to content

Commit 2247408

Browse files
authored
ci fixes (#871)
- **update working agreement** - **improve robustness of asset lookup...** - **fix: load timing issues w/ environment vars**
2 parents a196af0 + 4b6a9c7 commit 2247408

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

agent/u.working-agreement.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
This folder is the working scratchpad for user+assistant development.
1+
This folder is the working scratchpad for document-centric user+assistant development.
22

33
# Conventions
44

5+
Working sessions will usually be focused on a session-directory. Either a numbered directory (referring to a gh issue) or a directory named for the task at hand. New working documents should be created in this directory, and named according to the conventions below. For GH issues, please *do* use the `gh` command to *read* existing issues, PRs, and workflow runs.
6+
57
files prefixed with `u.` are user-authored.
68
files prefixed with `a.` are assistant-authored.
79

packages/express/src/app.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { createExpressApp, initializeServices } from './app-factory.js';
2-
import logger from './logger.js';
3-
import ENV from './utils/env.js';
41
import dotenv from 'dotenv';
5-
import { initializeCouchDB } from './couchdb/index.js';
6-
import { initializeDataLayer } from '@vue-skuilder/db';
72

3+
// Load environment variables FIRST before importing any modules that depend on them
84
dotenv.config({
95
path:
106
process.argv && process.argv.length == 3
117
? process.argv[2]
128
: '.env.development',
139
});
1410

15-
// Now that dotenv is configured, we can validate the environment
11+
// Now import modules that depend on environment variables
12+
import { createExpressApp, initializeServices } from './app-factory.js';
13+
import logger from './logger.js';
14+
import ENV from './utils/env.js';
15+
import { initializeCouchDB } from './couchdb/index.js';
16+
import { initializeDataLayer } from '@vue-skuilder/db';
17+
18+
// Validate that environment variables are loaded
1619
const requiredVars = ['COUCHDB_SERVER', 'COUCHDB_PROTOCOL', 'COUCHDB_ADMIN', 'COUCHDB_PASSWORD', 'VERSION', 'NODE_ENV'];
1720
const missingVars = requiredVars.filter(v => !process.env[v]);
1821

packages/express/src/design-docs.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,42 @@ function emit(key?: unknown, value?: unknown): [unknown, unknown] {
1515
const __filename = fileURLToPath(import.meta.url);
1616
const __dirname = dirname(__filename);
1717

18-
// Load design documents with absolute paths
18+
// Dual resolution strategy for assets
19+
function getAssetPath(assetName: string): string {
20+
// Strategy 1: Development mode - assets in parent directory
21+
const devModePath = join(__dirname, '..', 'assets', assetName);
22+
if (fileSystem.existsSync(devModePath)) {
23+
return devModePath;
24+
}
25+
26+
// Strategy 2: Built module mode - assets in same directory
27+
const moduleModePath = join(__dirname, 'assets', assetName);
28+
if (fileSystem.existsSync(moduleModePath)) {
29+
return moduleModePath;
30+
}
31+
32+
// Fallback error with helpful context
33+
throw new Error(
34+
`Asset '${assetName}' not found. Tried:\n` +
35+
` Dev mode: ${devModePath}\n` +
36+
` Module mode: ${moduleModePath}\n` +
37+
` Current __dirname: ${__dirname}`
38+
);
39+
}
40+
41+
// Load design documents with dual resolution
1942
export const classroomDbDesignDoc = fileSystem.readFileSync(
20-
join(__dirname, 'assets', 'classroomDesignDoc.js'),
43+
getAssetPath('classroomDesignDoc.js'),
2144
'utf-8'
2245
);
2346

2447
export const courseDBDesignDoc = fileSystem.readFileSync(
25-
join(__dirname, 'assets', 'get-tagsDesignDoc.json'),
48+
getAssetPath('get-tagsDesignDoc.json'),
2649
'utf-8'
2750
);
2851

2952
export const courseValidateDocUpdate = fileSystem.readFileSync(
30-
join(__dirname, 'assets', 'courseValidateDocUpdate.js'),
53+
getAssetPath('courseValidateDocUpdate.js'),
3154
'utf-8'
3255
);
3356

packages/express/src/utils/env.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ function getVar(name: string): string {
2020
}
2121
}
2222

23+
// Use getter to read environment variables lazily after dotenv has loaded
2324
const env: Env = {
24-
COUCHDB_SERVER: getVar('COUCHDB_SERVER'),
25-
COUCHDB_PROTOCOL: getVar('COUCHDB_PROTOCOL'),
26-
COUCHDB_ADMIN: getVar('COUCHDB_ADMIN'),
27-
COUCHDB_PASSWORD: getVar('COUCHDB_PASSWORD'),
28-
VERSION: getVar('VERSION'),
29-
NODE_ENV: getVar('NODE_ENV'),
25+
get COUCHDB_SERVER() { return getVar('COUCHDB_SERVER'); },
26+
get COUCHDB_PROTOCOL() { return getVar('COUCHDB_PROTOCOL'); },
27+
get COUCHDB_ADMIN() { return getVar('COUCHDB_ADMIN'); },
28+
get COUCHDB_PASSWORD() { return getVar('COUCHDB_PASSWORD'); },
29+
get VERSION() { return getVar('VERSION'); },
30+
get NODE_ENV() { return getVar('NODE_ENV'); },
3031
};
3132

3233
export default env;

0 commit comments

Comments
 (0)