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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ test-results/
wt/
coverage/
wt-last-updated
wt-i18n-sessionboard
4 changes: 1 addition & 3 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,7 @@ PATCH /v1/sessions/:id

Updates mutable session metadata fields. Currently supports pinning sessions to protect them from automatic reaping.

| Role | Required |
|------|----------|
| admin, operator | Yes |
> **Ownership:** Requires a valid API key that owns the session (enforced by `withOwnership`).

```bash
# Pin a session (reapers will never kill it)
Expand Down
89 changes: 54 additions & 35 deletions src/__tests__/otel-hostname-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,89 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';

// We test loadTracingConfig directly since it's a pure function
// that reads environment variables.
/**
* Tests for loadTracingConfig — hostname/PID env var handling.
*
* Issue: Argus audit found the previous test defined a local loadConfig()
* that duplicated loadTracingConfig() from src/tracing.ts. It never imported
* the real function — test passed even if the real code broke.
*
* Fix: Import the real loadTracingConfig with module isolation so env changes
* are picked up correctly.
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';

describe('loadTracingConfig — hostname/PID options', () => {
const originalEnv = { ...process.env };
const savedEnv: Record<string, string | undefined> = {};

const otelKeys = [
'AEGIS_OTEL_ENABLED',
'AEGIS_OTEL_SERVICE_NAME',
'AEGIS_OTEL_OTLP_ENDPOINT',
'AEGIS_OTEL_SAMPLE_RATE',
'AEGIS_OTEL_INCLUDE_HOSTNAME',
'AEGIS_OTEL_INCLUDE_PID',
];

beforeEach(() => {
for (const key of otelKeys) {
savedEnv[key] = process.env[key];
delete process.env[key];
}
});

afterEach(() => {
// Restore original env
process.env = { ...originalEnv };
for (const key of otelKeys) {
if (savedEnv[key] === undefined) {
delete process.env[key];
} else {
process.env[key] = savedEnv[key];
}
}
vi.resetModules();
});

function loadConfig() {
// Re-import to pick up env changes
// Using dynamic import with cache busting
const config = {
enabled: process.env.AEGIS_OTEL_ENABLED === 'true',
serviceName: process.env.AEGIS_OTEL_SERVICE_NAME || 'aegis',
otlpEndpoint: process.env.AEGIS_OTEL_OTLP_ENDPOINT || 'http://localhost:4318',
sampleRate: parseFloat(process.env.AEGIS_OTEL_SAMPLE_RATE || '1.0'),
includeHostname: process.env.AEGIS_OTEL_INCLUDE_HOSTNAME !== 'false',
includePid: process.env.AEGIS_OTEL_INCLUDE_PID !== 'false',
};
return config;
/** Import the real loadTracingConfig with fresh module cache. */
async function loadRealConfig() {
const { loadTracingConfig } = await import('../tracing.js');
return loadTracingConfig();
}

it('defaults includeHostname to true', () => {
delete process.env.AEGIS_OTEL_INCLUDE_HOSTNAME;
const config = loadConfig();
it('defaults includeHostname to true', async () => {
const config = await loadRealConfig();
expect(config.includeHostname).toBe(true);
});

it('defaults includePid to true', () => {
delete process.env.AEGIS_OTEL_INCLUDE_PID;
const config = loadConfig();
it('defaults includePid to true', async () => {
const config = await loadRealConfig();
expect(config.includePid).toBe(true);
});

it('sets includeHostname to false when AEGIS_OTEL_INCLUDE_HOSTNAME=false', () => {
it('sets includeHostname to false when AEGIS_OTEL_INCLUDE_HOSTNAME=false', async () => {
process.env.AEGIS_OTEL_INCLUDE_HOSTNAME = 'false';
const config = loadConfig();
const config = await loadRealConfig();
expect(config.includeHostname).toBe(false);
});

it('sets includePid to false when AEGIS_OTEL_INCLUDE_PID=false', () => {
it('sets includePid to false when AEGIS_OTEL_INCLUDE_PID=false', async () => {
process.env.AEGIS_OTEL_INCLUDE_PID = 'false';
const config = loadConfig();
const config = await loadRealConfig();
expect(config.includePid).toBe(false);
});

it('keeps includeHostname true for non-"false" values', () => {
it('keeps includeHostname true for non-"false" values', async () => {
process.env.AEGIS_OTEL_INCLUDE_HOSTNAME = 'yes';
const config = loadConfig();
const config = await loadRealConfig();
expect(config.includeHostname).toBe(true);
});

it('keeps includePid true for non-"false" values', () => {
it('keeps includePid true for non-"false" values', async () => {
process.env.AEGIS_OTEL_INCLUDE_PID = '0';
const config = loadConfig();
const config = await loadRealConfig();
expect(config.includePid).toBe(true);
});

it('both can be disabled simultaneously', () => {
it('both can be disabled simultaneously', async () => {
process.env.AEGIS_OTEL_INCLUDE_HOSTNAME = 'false';
process.env.AEGIS_OTEL_INCLUDE_PID = 'false';
const config = loadConfig();
const config = await loadRealConfig();
expect(config.includeHostname).toBe(false);
expect(config.includePid).toBe(false);
});
Expand Down
Loading