Fixed two critical bugs preventing ten-frames from rendering: 1. **Mastery mode not handled** (typstGenerator.ts:61) - Code only checked for 'smart' | 'manual' modes - Mastery mode fell into manual path, tried to use boolean flags that don't exist - Resulted in all display options being `undefined` - Fix: Check for both 'smart' OR 'mastery' modes (both use displayRules) 2. **Typst array membership syntax** (already fixed in previous commit) - Used `(i in array)` which doesn't work in Typst - Changed to `array.contains(i)` Added comprehensive unit tests (tenFrames.test.ts): - Problem analysis tests (regrouping detection) - Display rule evaluation tests - Full Typst template generation tests - Mastery mode specific tests - All 14 tests now passing Added debug logging to trace display rules resolution: - displayRules.ts: Shows rule evaluation per problem - typstGenerator.ts: Shows enriched problems and Typst data - Helps diagnose future issues The issue was that mastery mode (which uses displayRules like smart mode) was being treated as manual mode (which uses boolean flags), resulting in undefined display options. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
const { createServer } = require('http')
|
|
const { parse } = require('url')
|
|
const next = require('next')
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
const hostname = 'localhost'
|
|
const port = parseInt(process.env.PORT || '3000', 10)
|
|
|
|
const app = next({ dev, hostname, port })
|
|
const handle = app.getRequestHandler()
|
|
|
|
// Run migrations before starting server
|
|
console.log('🔄 Running database migrations...')
|
|
const { migrate } = require('drizzle-orm/better-sqlite3/migrator')
|
|
const { db } = require('./dist/db/index')
|
|
|
|
try {
|
|
migrate(db, { migrationsFolder: './drizzle' })
|
|
console.log('✅ Migrations complete')
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error)
|
|
process.exit(1)
|
|
}
|
|
|
|
app.prepare().then(() => {
|
|
const server = createServer(async (req, res) => {
|
|
try {
|
|
const parsedUrl = parse(req.url, true)
|
|
await handle(req, res, parsedUrl)
|
|
} catch (err) {
|
|
console.error('Error occurred handling', req.url, err)
|
|
res.statusCode = 500
|
|
res.end('internal server error')
|
|
}
|
|
})
|
|
|
|
// Debug: Check upgrade handlers at each stage
|
|
console.log('📊 Stage 1 - After server creation:')
|
|
console.log(` Upgrade handlers: ${server.listeners('upgrade').length}`)
|
|
|
|
// Initialize Socket.IO
|
|
const { initializeSocketServer } = require('./dist/socket-server')
|
|
|
|
console.log('📊 Stage 2 - Before initializeSocketServer:')
|
|
console.log(` Upgrade handlers: ${server.listeners('upgrade').length}`)
|
|
|
|
initializeSocketServer(server)
|
|
|
|
console.log('📊 Stage 3 - After initializeSocketServer:')
|
|
const allHandlers = server.listeners('upgrade')
|
|
console.log(` Upgrade handlers: ${allHandlers.length}`)
|
|
allHandlers.forEach((handler, i) => {
|
|
console.log(` [${i}] ${handler.name || 'anonymous'} (length: ${handler.length} params)`)
|
|
})
|
|
|
|
// Log all upgrade requests to see handler execution order
|
|
const originalEmit = server.emit.bind(server)
|
|
server.emit = (event, ...args) => {
|
|
if (event === 'upgrade') {
|
|
const req = args[0]
|
|
console.log(`\n🔄 UPGRADE REQUEST: ${req.url}`)
|
|
console.log(` ${allHandlers.length} handlers will be called`)
|
|
}
|
|
return originalEmit(event, ...args)
|
|
}
|
|
|
|
server
|
|
.once('error', (err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|
|
.listen(port, () => {
|
|
console.log(`> Ready on http://${hostname}:${port}`)
|
|
})
|
|
})
|