Files
TradarrV2/frontend/e2e/stack-manifest.mjs
Blomios d65222169a feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection.

Refs #19

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-22 15:08:22 +01:00

87 lines
3.4 KiB
JavaScript

import { readFileSync } from 'node:fs'
import { isIP } from 'node:net'
import { tmpdir } from 'node:os'
import path from 'node:path'
const requiredURLs = [
'frontendUrl',
'apiUrl',
'databaseUrl',
'openFigiFakeUrl',
'scraperFakeUrl',
'layaFakeUrl',
'fakeControlUrl',
]
function loopbackURL(value, field, protocols) {
let parsed
try {
parsed = new URL(value)
} catch {
throw new Error(`E2E fake stack manifest field ${field} must be a URL.`)
}
if (!protocols.includes(parsed.protocol)) {
throw new Error(`E2E fake stack manifest field ${field} uses an unsupported protocol.`)
}
const hostname = parsed.hostname.replace(/^\[|\]$/g, '')
const loopback = hostname === 'localhost' || hostname.endsWith('.localhost') ||
(isIP(hostname) === 4 && hostname.startsWith('127.')) || hostname === '::1'
if (!loopback) {
throw new Error(`E2E fake stack manifest field ${field} must use a loopback host.`)
}
return parsed
}
export function stackManifestPath() {
return process.env.TRADARR_E2E_STACK_MANIFEST ||
path.join(process.env.TMPDIR || tmpdir(), 'tradarr-e2e', 'stack.json')
}
export function readStackManifest() {
const manifestPath = stackManifestPath()
let manifest
try {
manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
} catch {
throw new Error([
`Safe E2E composition is missing: no readable stack manifest at ${manifestPath}.`,
'No browser, application server, database, or provider was started by this run.',
'The manifest must be produced by a loopback-only fake stack and point to a disposable E2E database.',
].join(' '))
}
if (manifest.networkPolicy !== 'loopback-only') {
throw new Error('E2E fake stack manifest must declare networkPolicy "loopback-only".')
}
if (manifest.generationProvider !== 'fake-laya') {
throw new Error('E2E fake stack manifest must declare generationProvider "fake-laya".')
}
for (const field of requiredURLs) {
if (typeof manifest[field] !== 'string' || !manifest[field]) {
throw new Error(`E2E fake stack manifest is missing ${field}.`)
}
loopbackURL(manifest[field], field, field === 'databaseUrl' ? ['postgres:', 'postgresql:'] : ['http:', 'https:'])
}
if (typeof manifest.psqlPath !== 'string' || !manifest.psqlPath.startsWith('/')) {
throw new Error('E2E fake stack manifest must provide an absolute psqlPath for database assertions.')
}
if (!manifest.bootstrapAdmin?.email || !manifest.bootstrapAdmin?.password) {
throw new Error('E2E fake stack manifest must provide disposable bootstrap admin credentials.')
}
for (const field of ['companyQuery', 'companyID', 'companyName', 'companySymbol', 'companyFIGI', 'summaryModelID', 'summarySentinel', 'articleTitle', 'articleURL', 'articleContent', 'candidateID']) {
if (typeof manifest.fixtures?.[field] !== 'string' || !manifest.fixtures[field]) {
throw new Error(`E2E fake stack manifest is missing fixtures.${field}.`)
}
}
const databaseURL = new URL(manifest.databaseUrl)
const databaseName = decodeURIComponent(databaseURL.pathname.replace(/^\//, ''))
if (!/(^|[-_])(e2e|test)([-_]|$)/i.test(databaseName)) {
throw new Error('E2E database name must identify a disposable database with an e2e or test marker.')
}
if (!manifest.fakeAuditPath || !manifest.fakeAuditPath.startsWith('/')) {
throw new Error('E2E fake stack manifest must provide an absolute fakeAuditPath.')
}
return { ...manifest, databaseURL }
}