AI CCTV 목적을 원론부터 재점검한 결과. 셋 다 새 추론 모델 없이 지금 있는 자세추정·구역·트랙 이력만으로 구현했다. ■ 추락 (fall_from_height) 잡고 있던 것은 같은 높이의 '넘어짐'이었고, 사망 1위 유형인 '떨어짐'은 못 잡았다. GhostIncidentDetector 가 트랙이 이미 위험 자세일 때만 무장하므로 (_DANGEROUS), 발판에 서 있다가 떨어지는 사람은 소실 순간 STANDING 이라 아무것도 안 걸렸다. 판정의 핵심은 bbox 중심이 아니라 하단(y2)이다. 쭈그려 앉으면 중심은 내려가도 발은 그 자리이고, 추락은 발 밑선이 통째로 내려간다 — 중심으로 재면 쭈그려 앉아 작업하는 사람이 전부 추락이 된다. 원근 접근은 y2 도 내려가므로 높이 증가 가드로 따로 막는다. Track.frames 가 90프레임을 들고 있어 별도 버퍼가 없다. 발보는 두 갈래로 나뉘되 한 사고는 한 건이다: 프레임 안에서 넘어짐이 확정되면 유형을 승격하고, 화각 밖으로 사라지면 ghost 무장을 넓혀 그쪽으로 낸다. 심각도 CRITICAL — 척추·두부 손상 주의가 통보에 실리려면 넘어짐(HIGH)과 등급이 갈라져야 한다. 고소 구역은 rules_json 의 elevated 키로 붙어 스키마 변경이 없고, 구역이 없어도 하강 신호만으로 동작한다. ■ 동시 다발 쓰러짐 (multi_down) 같은 구역에서 짧은 시간에 둘이 쓰러진 것은 넘어짐 두 건이 아니라 질식· 가스·폭발이다. 이 기능의 본체는 감지가 아니라 통보 문구다 — 밀폐공간 사망자의 상당수가 구조하러 들어간 사람이므로, 링크를 열기 전에 메일 본문에서 "공기호흡기 없이 진입하지 마십시오"가 읽혀야 한다. Channels::guidance 로 유형별 안내를 붙였고 문구를 테스트로 고정했다(문구가 사라지면 기능이 사라진 것과 같다). 서버에 둔 이유: 가스는 카메라 화각을 존중하지 않아 노드를 넘는 판단이 필요하고, 현장 즉시 대응은 첫 쓰러짐의 경광등이 이미 확보한다. 오탐 방어의 핵심은 근접성 — 넓은 공장에서 2분 안의 무관한 넘어짐 두 건은 실제로 일어나므로 같은 구역이거나 좌표가 가까워야 묶는다. 한 사람이 두 번 넘어진 것은 한 명으로 센다. ■ 구역 프리셋 6종 + max_workers:0 수정 밀폐공간 감시에 필요한 것(제한구역+2인1조+체류상한)은 이미 전부 있었는데 화면이 "최소 인원을 넣으세요"라고만 물어 아무도 그렇게 쓰지 못했다. 안전관리자는 min_workers 가 아니라 밀폐공간을 생각한다. 그 과정에서 잠복 결함 하나: max_workers:0 이 falsy 로 걸러져 "아무도 있으면 안 되는 구역"(크레인 짐 아래·굴착기 선회 반경 = 깔림 사고의 전형)이 통째로 꺼져 있었다. 운영자가 저장해 놓고도 아무 일이 안 일어났다. 감지기·입력란 (min=1)·저장 직렬화(>0)·목록 표시 네 곳에서 막혀 있었다. ■ 검증 pytest 322 passed / phpunit 263 passed. 신규 테스트 30건. 이벤트 유형 2종 추가는 test_event_type_parity 가 강제하는 5곳(엣지 enum · EventValidator · schema CHECK · 프런트 라벨 5파일 · 필터 옵션) 전부 동기화했고 기존 설치용 마이그레이션을 추가했다. ■ Pi 번들 1.1.0 과 달리 이번에는 edge/ 가 바뀌었으므로 Pi 번들 재빌드가 필수다. 낡은 1.0.0 번들은 dist/ 에서 제거했다 — 두면 추락 감지가 빠진 노드가 그대로 납품된다. arm64 + 네트워크 빌드 머신에서 재빌드해야 Pi 납품이 가능하다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EBjuR7DW6PNNMows4KnbYU
99 lines
4.9 KiB
PHP
99 lines
4.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Guards the REAL route table in public/index.php.
|
|
*
|
|
* WiringSmokeTest exercises the Router's matching algorithm against dummy handlers it registers
|
|
* itself — it never reads index.php, so a route deleted, misspelled, or never added there does
|
|
* not fail any test. index.php cannot simply be require'd (it dispatches on load and touches
|
|
* superglobals), so this parses its registrations instead.
|
|
*
|
|
* That matters most for an air-gapped delivery: a missing route is invisible until an operator
|
|
* on a site with no internet clicks the button.
|
|
*/
|
|
final class RouteTableTest extends TestCase
|
|
{
|
|
/** @return list<string> "METHOD path" pairs registered in index.php */
|
|
private function registeredRoutes(): array
|
|
{
|
|
$src = file_get_contents(dirname(__DIR__) . '/public/index.php');
|
|
$this->assertNotFalse($src, 'index.php unreadable');
|
|
preg_match_all("/\\\$r->add\(\s*'([A-Z]+)'\s*,\s*'([^']+)'/", $src, $m, PREG_SET_ORDER);
|
|
return array_map(static fn ($x) => $x[1] . ' ' . $x[2], $m);
|
|
}
|
|
|
|
public function testEveryExpectedRouteIsRegistered(): void
|
|
{
|
|
// Adding a route must also update this list — that is the point: the list is the
|
|
// reviewed inventory of the app's public surface.
|
|
$expected = [
|
|
'POST /api/events', 'POST /api/heartbeat', 'GET /api/config', 'GET /api/csrf',
|
|
'POST /login', 'POST /logout', 'GET /api/events', 'GET /api/devices',
|
|
'GET /events/{id}', 'POST /events/{id}/ack', 'POST /events/{id}/false-positive',
|
|
'GET /api/zones/{camera}', 'GET /api/zone-presets',
|
|
'GET /api/heatmap/{camera}', 'GET /api/fp-stats',
|
|
'GET /api/report', 'GET /api/export/labels', 'GET /api/actions', 'POST /api/actions',
|
|
'GET /api/cameras/{camera}/latest-snapshot', 'POST /api/zones',
|
|
'POST /api/zones/{id}/delete', 'GET /snap/{uuid}',
|
|
// 성능 추이 · 임계값 · 통보 채널 · 억제 · 위험성평가 · 인수인계 · 사고조사 패키지
|
|
'GET /api/devices/{id}/metrics',
|
|
'GET /api/admin/thresholds', 'POST /api/admin/thresholds',
|
|
'POST /api/admin/thresholds/{id}/delete',
|
|
'GET /api/admin/channels', 'POST /api/admin/channels',
|
|
'POST /api/admin/channels/{id}/delete',
|
|
'GET /api/suppressions', 'POST /api/suppressions', 'POST /api/suppressions/{id}/revoke',
|
|
'GET /api/risks', 'POST /api/risks', 'POST /api/risks/{id}/delete',
|
|
'GET /api/handovers', 'POST /api/handovers',
|
|
'GET /api/events/{id}/package',
|
|
'GET /', 'GET /login', 'GET /zones', 'GET /report', 'GET /events/{id}/view',
|
|
'GET /admin', 'GET /compliance', 'GET /setup', 'GET /events/{id}/package/view',
|
|
];
|
|
$actual = $this->registeredRoutes();
|
|
sort($expected);
|
|
$sorted = $actual;
|
|
sort($sorted);
|
|
$this->assertSame($expected, $sorted);
|
|
}
|
|
|
|
public function testNoRouteIsRegisteredTwice(): void
|
|
{
|
|
// A duplicate silently shadows the first registration (first match wins) — the kind of
|
|
// copy-paste slip that survives review because both lines look correct in isolation.
|
|
$routes = $this->registeredRoutes();
|
|
$this->assertSame(array_values(array_unique($routes)), $routes);
|
|
}
|
|
|
|
public function testEveryEndpointTheFrontendCallsExists(): void
|
|
{
|
|
// The frontend is vanilla JS with no build step, so a typo'd URL is caught by nothing —
|
|
// no bundler, no type checker. Cross-check the two halves against each other.
|
|
$registered = array_map(static fn ($r) => explode(' ', $r, 2)[1], $this->registeredRoutes());
|
|
|
|
$calls = [];
|
|
foreach (glob(dirname(__DIR__) . '/public/assets/*.js') as $js) {
|
|
preg_match_all("/B \+ '([^']+)'/", (string)file_get_contents($js), $m);
|
|
foreach ($m[1] as $raw) {
|
|
// The JS concatenates ids onto a literal prefix ("B + '/events/' + id"), so what
|
|
// is visible here is a PREFIX, not a full path. Strip the query string and the
|
|
// trailing slash to get the literal part.
|
|
$path = rtrim(strtok($raw, '?'), '/');
|
|
$calls[$path === '' ? '/' : $path] = basename($js);
|
|
}
|
|
}
|
|
|
|
foreach ($calls as $path => $file) {
|
|
// Match on a SEGMENT boundary: '/events' is satisfied by '/events/{id}', but a typo
|
|
// like '/api/actio' is NOT satisfied by '/api/actions' (no '/api/actio/' route).
|
|
$hit = in_array($path, $registered, true);
|
|
foreach ($registered as $route) {
|
|
if ($hit) break;
|
|
$hit = str_starts_with($route, rtrim($path, '/') . '/');
|
|
}
|
|
$this->assertTrue($hit, "$file calls $path but index.php registers no such route");
|
|
}
|
|
}
|
|
}
|