From 91d8a58d1ed1da9c7cd4d68df7f4baed06e3693e Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Fri, 6 Nov 2026 09:04:37 +1100 Subject: [PATCH 1/5] Require verified email through shared JWT verifier --- package.json | 2 +- pnpm-lock.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index daf0f08..3090d20 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "pg": "^8.16.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.2", - "tc-core-library-js": "github:topcoder-platform/tc-core-library-js#v4.0.0-rc.2" + "tc-core-library-js": "https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 29b3ca1..42a1f73 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,8 +96,8 @@ importers: specifier: ^7.8.2 version: 7.8.2 tc-core-library-js: - specifier: github:topcoder-platform/tc-core-library-js#v4.0.0-rc.2 - version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/58de37670180e183e8378c3d203df0112a0414f6(supports-color@8.1.1) + specifier: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4 + version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4(supports-color@8.1.1) devDependencies: '@eslint/eslintrc': specifier: ^3.2.0 @@ -3161,9 +3161,9 @@ packages: resolution: {integrity: sha512-Re10+NauLTMCudc7T5WLFLAwDhQ0JWdrMK+9B2M8zR5hRExKmsRDCBA7/aV/pNJFltmBFO5BAMlQFi/vq3nKOg==} engines: {node: '>=6'} - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/58de37670180e183e8378c3d203df0112a0414f6: - resolution: {gitHosted: true, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/58de37670180e183e8378c3d203df0112a0414f6} - version: 4.0.0-rc.2 + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4: + resolution: {gitHosted: true, integrity: sha512-4xzx6ycEdy8Rs5BpIOUhg/YX0cUUQpOCtTM60vcb9JF4XvqI1fLfIDmHNvZNek49dBo1Il1Lp8O/HLhKfLhhVg==, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4} + version: 4.0.0-rc.4 engines: {node: '>=22.13'} terser-webpack-plugin@5.3.14: @@ -6928,7 +6928,7 @@ snapshots: tapable@2.2.2: {} - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/58de37670180e183e8378c3d203df0112a0414f6(supports-color@8.1.1): + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4(supports-color@8.1.1): dependencies: '@types/jsonwebtoken': 9.0.10 jsonwebtoken: 9.0.3 From 5021c44c16c40ab935244e95a2f9a49882827b54 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Fri, 6 Nov 2026 09:22:18 +1100 Subject: [PATCH 2/5] Use compatible v4 verification backport and verified JWT fixtures --- package.json | 2 +- pnpm-lock.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 3090d20..6a2f65d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "pg": "^8.16.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.2", - "tc-core-library-js": "https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4" + "tc-core-library-js": "https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42a1f73..e53f7b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,8 +96,8 @@ importers: specifier: ^7.8.2 version: 7.8.2 tc-core-library-js: - specifier: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4 - version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4(supports-color@8.1.1) + specifier: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a + version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a(supports-color@8.1.1) devDependencies: '@eslint/eslintrc': specifier: ^3.2.0 @@ -3161,9 +3161,9 @@ packages: resolution: {integrity: sha512-Re10+NauLTMCudc7T5WLFLAwDhQ0JWdrMK+9B2M8zR5hRExKmsRDCBA7/aV/pNJFltmBFO5BAMlQFi/vq3nKOg==} engines: {node: '>=6'} - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4: - resolution: {gitHosted: true, integrity: sha512-4xzx6ycEdy8Rs5BpIOUhg/YX0cUUQpOCtTM60vcb9JF4XvqI1fLfIDmHNvZNek49dBo1Il1Lp8O/HLhKfLhhVg==, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4} - version: 4.0.0-rc.4 + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a: + resolution: {gitHosted: true, integrity: sha512-n+4KUOeV4LEIsTI/R216dBc6bUkbSyO/2O0LpoY3Hk7eqKsRQFUHloB3y0hfK/v1rzf8qYQxTdv8ikeRGBn4pQ==, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a} + version: 4.0.0-rc.2.1 engines: {node: '>=22.13'} terser-webpack-plugin@5.3.14: @@ -6928,7 +6928,7 @@ snapshots: tapable@2.2.2: {} - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/2067e74f73d7fe3442c96f375fc97f8486f79be4(supports-color@8.1.1): + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a(supports-color@8.1.1): dependencies: '@types/jsonwebtoken': 9.0.10 jsonwebtoken: 9.0.3 From 8703c5a060aa7b9a4ec85a04741348c5f07e1cc2 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Thu, 12 Nov 2026 09:48:18 +1100 Subject: [PATCH 3/5] Ignore non-member submission identifiers in statistics reports --- .../design/first-time-design-submitters.sql | 5 +- .../first-time-development-submitters.sql | 5 +- test/statistics/README.md | 19 ++++++ test/statistics/test_first_submitters.py | 61 +++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 test/statistics/README.md create mode 100644 test/statistics/test_first_submitters.py diff --git a/sql/reports/statistics/design/first-time-design-submitters.sql b/sql/reports/statistics/design/first-time-design-submitters.sql index a411d60..c49d297 100644 --- a/sql/reports/statistics/design/first-time-design-submitters.sql +++ b/sql/reports/statistics/design/first-time-design-submitters.sql @@ -1,6 +1,9 @@ WITH development_submissions_ranked AS ( SELECT - s."memberId"::bigint AS member_id, + CASE WHEN s."memberId" ~ '^[0-9]{1,19}$' THEN + CASE WHEN s."memberId"::numeric <= 9223372036854775807 + THEN s."memberId"::bigint END + END AS member_id, s."challengeId" AS challenge_id, s."submittedDate" AS submitted_date, ROW_NUMBER() OVER ( diff --git a/sql/reports/statistics/development/first-time-development-submitters.sql b/sql/reports/statistics/development/first-time-development-submitters.sql index 280a4ff..060434a 100644 --- a/sql/reports/statistics/development/first-time-development-submitters.sql +++ b/sql/reports/statistics/development/first-time-development-submitters.sql @@ -1,6 +1,9 @@ WITH development_submissions_ranked AS ( SELECT - s."memberId"::bigint AS member_id, + CASE WHEN s."memberId" ~ '^[0-9]{1,19}$' THEN + CASE WHEN s."memberId"::numeric <= 9223372036854775807 + THEN s."memberId"::bigint END + END AS member_id, s."challengeId" AS challenge_id, s."submittedDate" AS submitted_date, ROW_NUMBER() OVER ( diff --git a/test/statistics/README.md b/test/statistics/README.md new file mode 100644 index 0000000..4877fe0 --- /dev/null +++ b/test/statistics/README.md @@ -0,0 +1,19 @@ +# First-time submitter SQL regression + +The public Design report failed with HTTP 500 when a submission's memberId was an +M2M client identifier (`…@clients`). Both first-time-submitter queries cast that +field to bigint. Guard the cast inside CASE so PostgreSQL predicate reordering +cannot evaluate it for non-member or out-of-range identifiers. Valid members, +earliest submissions, the three-month window, and maximum ratings are unchanged. + +Run the actual queries against PostgreSQL 16 with: + +```sh +STATISTICS_PSQL_COMMAND='psql postgresql://localhost/test_database' \ + python3 -m unittest discover -s test/statistics +``` + +The test uses unique fixture schemas in a rolled-back transaction. It includes +service accounts, null/empty/oversized identifiers, returning members, multiple +submissions, duplicate ratings, and an unrated member. No application tables are +changed. Without STATISTICS_PSQL_COMMAND the integration test is skipped. diff --git a/test/statistics/test_first_submitters.py b/test/statistics/test_first_submitters.py new file mode 100644 index 0000000..26d6da8 --- /dev/null +++ b/test/statistics/test_first_submitters.py @@ -0,0 +1,61 @@ +"""Run real PostgreSQL regressions with STATISTICS_PSQL_COMMAND set to a psql command. + +Example: STATISTICS_PSQL_COMMAND='docker exec -i statistics-query-tests psql -U postgres' +python3 -m unittest discover -s test/statistics +Uses transactional, uniquely named fixture schemas; no application tables are changed. +""" +import os +from pathlib import Path +import shlex +import subprocess +import unittest +import uuid + + +@unittest.skipUnless(os.environ.get('STATISTICS_PSQL_COMMAND'), 'PostgreSQL command not configured') +class FirstSubmittersTest(unittest.TestCase): + def test_reports_ignore_non_member_identifiers_without_losing_first_submission_semantics(self): + root = Path(__file__).resolve().parents[2] + for track, abbreviation in [('design', 'DS'), ('development', 'Dev')]: + with self.subTest(track=track): + suffix = uuid.uuid4().hex + schemas = {name: f'stats_test_{name}_{suffix}' for name in ['members', 'reviews', 'challenges']} + query = (root / f'sql/reports/statistics/{track}/first-time-{track}-submitters.sql').read_text() + sql = '''BEGIN; +CREATE SCHEMA members; +CREATE SCHEMA reviews; +CREATE SCHEMA challenges; +CREATE TABLE members.member ("userId" bigint, handle text); +CREATE TABLE members."memberMaxRating" ("userId" bigint, rating int); +CREATE TABLE challenges."ChallengeTrack" (id text, abbreviation text); +CREATE TABLE challenges."Challenge" (id text, name text, "trackId" text); +CREATE TABLE reviews.submission ("memberId" text, "challengeId" text, "submittedDate" timestamptz); +INSERT INTO members.member VALUES (101, 'new-member'), (102, 'returning-member'), (103, 'no-rating'); +INSERT INTO members."memberMaxRating" VALUES (101, 1000), (101, 1500); +INSERT INTO challenges."ChallengeTrack" VALUES ('track', 'TRACK_ABBREVIATION'); +INSERT INTO challenges."Challenge" VALUES ('first', 'First challenge', 'track'), ('second', 'Second challenge', 'track'); +INSERT INTO reviews.submission VALUES + ('101', 'first', now() - interval '2 days'), ('101', 'second', now() - interval '1 day'), + ('102', 'first', now() - interval '1 year'), ('102', 'second', now() - interval '1 day'), + ('103', 'first', now() - interval '1 day'), + ('service-account@clients', 'first', now()), ('', 'first', now()), + ('9223372036854775808', 'first', now()), ('999999999999999999999999999', 'first', now()), + (NULL, 'first', now()); +CREATE TEMP TABLE actual AS +QUERY +DO $$ BEGIN + IF (SELECT count(*) FROM actual) <> 2 THEN RAISE EXCEPTION 'Expected two real first-time members'; END IF; + IF NOT EXISTS (SELECT FROM actual WHERE "user.handle" = 'new-member' + AND "challenge.challenge_name" = 'First challenge' AND "submitter_profile.max_rating" = 1500) + THEN RAISE EXCEPTION 'Lost earliest submission or highest rating'; END IF; + IF NOT EXISTS (SELECT FROM actual WHERE "user.handle" = 'no-rating' AND "submitter_profile.max_rating" IS NULL) + THEN RAISE EXCEPTION 'Lost unrated member'; END IF; +END $$; +ROLLBACK; +'''.replace('TRACK_ABBREVIATION', abbreviation).replace('QUERY', query) + for name, replacement in schemas.items(): + sql = sql.replace(f'CREATE SCHEMA {name};', f'CREATE SCHEMA {replacement};') + sql = sql.replace(name + '.', replacement + '.') + result = subprocess.run(shlex.split(os.environ['STATISTICS_PSQL_COMMAND']) + ['-X', '-v', 'ON_ERROR_STOP=1'], + input=sql, text=True, capture_output=True) + self.assertEqual(0, result.returncode, result.stderr) From cc6bd706c9ab3951a12fd990b02536416969d57d Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Sun, 15 Nov 2026 16:34:10 +1100 Subject: [PATCH 4/5] Patch vulnerable dependencies and Node container runtime --- Dockerfile | 4 ++-- pnpm-lock.yaml | 25 +++++++++++++------------ pnpm-workspace.yaml | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index cbf3285..31be301 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG NODE_VERSION=26.12.1 +ARG NODE_VERSION=26.13.1 ARG PNPM_VERSION=11.15.1 # ---- Build Base Stage ---- @@ -38,7 +38,7 @@ WORKDIR /usr/src/app # Alpine replaces old package revisions; constrain Node to the builder's major # version while allowing supported minor/patch releases and packaging revisions. RUN apk upgrade --no-cache \ - && apk add --no-cache ca-certificates "nodejs-current~${NODE_VERSION%%.*}" \ + && apk add --no-cache 'zlib>=1.4-r0' ca-certificates "nodejs-current~${NODE_VERSION%%.*}" "nodejs-current>=${NODE_VERSION}-r0" \ && addgroup -S -g 10001 app \ && adduser -S -D -u 10001 -G app -h /home/app app diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 29b3ca1..e099e4b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,8 +14,8 @@ overrides: qs: 6.16.1 handlebars: 4.7.10 mysql2: 3.23.1 - hono: 4.13.11 - '@hono/node-server': 2.1.3 + hono: 4.13.18 + '@hono/node-server': 2.1.8 js-yaml@^3: 3.15.2 js-yaml@^4: 4.3.2 brace-expansion@^1: 1.1.21 @@ -442,11 +442,11 @@ packages: resolution: {integrity: sha512-Z5kJ+wU3oA7MMIqVR9tyZRtjYPr4OC004Q4Rw7pgOKUOKkJfZ3O24nz3WYfGRpMDNmcOi3TwQOmgm7B7Tpii0w==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@hono/node-server@2.1.3': - resolution: {integrity: sha512-TA//nWMqPhbfdfneACk6t5a9eqbS9lABEPyKn0/xZTah3H3U2XaVg85rJFl0/Fyit0I552YDHgXGVSf3GwqbUw==} + '@hono/node-server@2.1.8': + resolution: {integrity: sha512-jdf7FHh6A1lzjpHHQUgxsg2GeER2vMetnAOfeActzcoli6jamlK+NAwL6Dsr5Fl3BS3tYUQzCdtZjU8Qxv7bEA==} engines: {node: '>=20'} peerDependencies: - hono: 4.13.11 + hono: 4.13.18 '@humanfs/core@0.19.2': resolution: {integrity: sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==} @@ -2052,8 +2052,8 @@ packages: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} - hono@4.13.11: - resolution: {integrity: sha512-/SMX/RQNJn7oNmFwH6DtwDqcrzZU2otm1FD6OJe2cWF6cfy/F8hq0XVBv7xW3FTJshRQwuBnXHDq2kNsdZnshg==} + hono@4.13.18: + resolution: {integrity: sha512-H9q/E1XizaWstJxUW881dmLxEj+t/TrGGnyxINkm4+sK0qUwsMtFdo2BWI9Vs3cIS19MU6b6iCijoUoEf4f3DA==} engines: {node: '>=16.9.0'} html-escaper@2.0.2: @@ -2616,6 +2616,7 @@ packages: node-abort-controller@3.1.1: resolution: {integrity: sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==} + deprecated: This package is no longer needed on supported Node.js versions. Node.js 16+ includes AbortController and AbortSignal as built-in globals. All Node.js versions requiring this polyfill are end-of-life. Use the built-in globals instead. node-emoji@1.11.0: resolution: {integrity: sha512-wo2DpQkQp7Sjm2A0cq+sN7EHKO6Sl0ctXeBdFZrL9T9+UywORbufTcTZxom8YqpLQt/FqNMUkOpkZrJVYSKD3A==} @@ -3793,9 +3794,9 @@ snapshots: '@eslint/core': 0.15.2 levn: 0.4.1 - '@hono/node-server@2.1.3(hono@4.13.11)': + '@hono/node-server@2.1.8(hono@4.13.18)': dependencies: - hono: 4.13.11 + hono: 4.13.18 '@humanfs/core@0.19.2': dependencies: @@ -4338,13 +4339,13 @@ snapshots: '@electric-sql/pglite': 0.3.2 '@electric-sql/pglite-socket': 0.0.6(@electric-sql/pglite@0.3.2) '@electric-sql/pglite-tools': 0.2.7(@electric-sql/pglite@0.3.2) - '@hono/node-server': 2.1.3(hono@4.13.11) + '@hono/node-server': 2.1.8(hono@4.13.18) '@mrleebo/prisma-ast': 0.12.1 '@prisma/get-platform': 6.8.2 '@prisma/query-plan-executor': 6.18.0 foreground-child: 3.3.1 get-port-please: 3.1.2 - hono: 4.13.11 + hono: 4.13.18 http-status-codes: 2.3.0 pathe: 2.0.3 proper-lockfile: 4.1.2 @@ -5705,7 +5706,7 @@ snapshots: dependencies: function-bind: 1.1.2 - hono@4.13.11: {} + hono@4.13.18: {} html-escaper@2.0.2: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 2c5ff0d..c280be4 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -11,8 +11,8 @@ overrides: 'qs': 6.16.1 'handlebars': 4.7.10 'mysql2': 3.23.1 - 'hono': 4.13.11 - '@hono/node-server': 2.1.3 + 'hono': 4.13.18 + '@hono/node-server': 2.1.8 'js-yaml@^3': 3.15.2 'js-yaml@^4': 4.3.2 'brace-expansion@^1': 1.1.21 From a51defa92f1d68e2d530b4b0029cba0c187550f9 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Tue, 17 Nov 2026 07:35:09 +0200 Subject: [PATCH 5/5] PM-6737 - ai assisted submissions report --- .../challenges/ai-assisted-submissions.sql | 32 +++++++ src/app-constants.ts | 2 + .../challenges/challenge-export-sql.spec.ts | 10 ++ .../challenges-reports.controller.ts | 23 +++++ .../challenges-reports.service.spec.ts | 44 +++++++++ .../challenges/challenges-reports.service.ts | 29 ++++++ .../dtos/ai-assisted-submissions.dto.ts | 91 +++++++++++++++++++ src/reports/report-directory.data.ts | 65 ++++++++++--- 8 files changed, 285 insertions(+), 11 deletions(-) create mode 100644 sql/reports/challenges/ai-assisted-submissions.sql create mode 100644 src/reports/challenges/dtos/ai-assisted-submissions.dto.ts diff --git a/sql/reports/challenges/ai-assisted-submissions.sql b/sql/reports/challenges/ai-assisted-submissions.sql new file mode 100644 index 0000000..a9b5ec5 --- /dev/null +++ b/sql/reports/challenges/ai-assisted-submissions.sql @@ -0,0 +1,32 @@ +-- PM-6737: submissions where the member answered the submit-page question +-- "Did AI tools ... most of your submission?" (reviews.submission."aiAssisted"). +SELECT + c.id AS "challengeId", + c.name AS "challengeName", + ctr.name AS "challengeTrack", + cty.name AS "challengeType", + c.status AS "challengeStatus", + s.id AS "submissionId", + s.type AS "submissionType", + s."memberId" AS "memberId", + m.handle AS "submitterHandle", + s."aiAssisted" AS "aiAssisted", + COALESCE(s."submittedDate", s."createdAt") AS "submittedDate" +FROM reviews."submission" s +JOIN challenges."Challenge" c + ON c.id = s."challengeId" +LEFT JOIN challenges."ChallengeTrack" ctr + ON ctr.id = c."trackId" +LEFT JOIN challenges."ChallengeType" cty + ON cty.id = c."typeId" +LEFT JOIN members."member" m + ON m."userId"::text = s."memberId" +WHERE s."aiAssisted" IS NOT NULL + -- filter by challenge + AND ($1::text IS NULL OR c.id = $1::text) + -- filter by challenge status + AND ($2::text[] IS NULL OR c.status::text = ANY($2::text[])) + -- filter by submission date bounds + AND ($3::timestamptz IS NULL OR COALESCE(s."submittedDate", s."createdAt") >= $3::timestamptz) + AND ($4::timestamptz IS NULL OR COALESCE(s."submittedDate", s."createdAt") <= $4::timestamptz) +ORDER BY COALESCE(s."submittedDate", s."createdAt") DESC, s.id; diff --git a/src/app-constants.ts b/src/app-constants.ts index bed47f8..78a10ca 100644 --- a/src/app-constants.ts +++ b/src/app-constants.ts @@ -35,6 +35,7 @@ export const Scopes = { Submitters: "reports:challenge-submitters", ValidSubmitters: "reports:challenge-valid-submitters", Winners: "reports:challenge-winners", + AiAssistedSubmissions: "reports:challenge-ai-assisted-submissions", }, Identity: { UsersByRole: "reports:identity-users-by-role", @@ -70,6 +71,7 @@ export const ScopeRoleAccess: Record = { [Scopes.Challenge.Submitters]: challengeReportAccessRoles, [Scopes.Challenge.ValidSubmitters]: challengeReportAccessRoles, [Scopes.Challenge.Winners]: challengeReportAccessRoles, + [Scopes.Challenge.AiAssistedSubmissions]: challengeReportAccessRoles, [Scopes.SFDC.PaymentsReport]: sfdcReportsTalentManagerRoles, [Scopes.SFDC.ChallengesReport]: sfdcReportsTalentManagerRoles, [Scopes.SFDC.BA]: sfdcReportsTalentManagerRoles, diff --git a/src/reports/challenges/challenge-export-sql.spec.ts b/src/reports/challenges/challenge-export-sql.spec.ts index 2023771..247b94d 100644 --- a/src/reports/challenges/challenge-export-sql.spec.ts +++ b/src/reports/challenges/challenge-export-sql.spec.ts @@ -97,4 +97,14 @@ describe("Challenge export SQL", () => { "WHEN wm.is_marathon_match AND wm.is_completed THEN wm.placement", ); }); + + it("only exports submissions with an AI-usage answer", () => { + const sql = sqlLoader.load( + "reports/challenges/ai-assisted-submissions.sql", + ); + + expect(sql).toContain(`WHERE s."aiAssisted" IS NOT NULL`); + expect(sql).toContain(`s."aiAssisted" AS "aiAssisted"`); + expect(sql).toContain("($1::text IS NULL OR c.id = $1::text)"); + }); }); diff --git a/src/reports/challenges/challenges-reports.controller.ts b/src/reports/challenges/challenges-reports.controller.ts index c5c43bb..5001b4b 100644 --- a/src/reports/challenges/challenges-reports.controller.ts +++ b/src/reports/challenges/challenges-reports.controller.ts @@ -27,6 +27,10 @@ import { SubmissionLinksQueryDto, } from "./dtos/submission-links.dto"; import { ChallengeUsersPathParamDto } from "./dtos/challenge-users.dto"; +import { + AiAssistedSubmissionDto, + AiAssistedSubmissionsQueryDto, +} from "./dtos/ai-assisted-submissions.dto"; @ApiTags("Challenges Reports") @ApiProduces("application/json", "text/csv") @@ -86,6 +90,25 @@ export class ChallengesReportsController { return report; } + @Get("/ai-assisted-submissions") + @UseGuards(PermissionsGuard) + @Scopes(AppScopes.AllReports, AppScopes.Challenge.AiAssistedSubmissions) + @ApiBearerAuth() + @ApiOperation({ + summary: + "Return submissions whose submitters answered the AI-usage question", + }) + @ApiResponse({ + status: 200, + description: "Export successful.", + type: ResponseDto, + }) + async getAiAssistedSubmissions( + @Query() query: AiAssistedSubmissionsQueryDto, + ) { + return this.reportsService.getAiAssistedSubmissions(query); + } + @Get("/:challengeId/registered-users") @UseGuards(PermissionsGuard) @Scopes(AppScopes.AllReports, AppScopes.Challenge.RegisteredUsers) diff --git a/src/reports/challenges/challenges-reports.service.spec.ts b/src/reports/challenges/challenges-reports.service.spec.ts index 91e5c17..f0f552f 100644 --- a/src/reports/challenges/challenges-reports.service.spec.ts +++ b/src/reports/challenges/challenges-reports.service.spec.ts @@ -224,4 +224,48 @@ describe("ChallengesReportsService", () => { expect(result[0]).not.toHaveProperty("finalScore"); expect(result[0]).not.toHaveProperty("finalRank"); }); + + it("passes AI-assisted submission filters to the report query in order", async () => { + const rows = [ + { + challengeId: "challenge-id", + challengeName: "Marathon Match 165", + challengeTrack: "Data Science", + challengeType: "Marathon Match", + challengeStatus: "ACTIVE", + submissionId: "submission-id", + submissionType: "CONTEST_SUBMISSION", + memberId: "123", + submitterHandle: "member", + aiAssisted: true, + submittedDate: "2026-11-12T10:00:00.000Z", + }, + ]; + db.query.mockResolvedValue(rows); + + const result = await service.getAiAssistedSubmissions({ + challengeId: "challenge-id", + challengeStatus: ["ACTIVE"] as any, + submittedDateFrom: "2026-11-01T00:00:00.000Z", + }); + + expect(sql.load).toHaveBeenCalledWith( + "reports/challenges/ai-assisted-submissions.sql", + ); + expect(db.query).toHaveBeenCalledWith("SELECT 1", [ + "challenge-id", + ["ACTIVE"], + "2026-11-01T00:00:00.000Z", + null, + ]); + expect(result).toEqual(rows); + }); + + it("sends null for every omitted AI-assisted submission filter", async () => { + db.query.mockResolvedValue([]); + + await service.getAiAssistedSubmissions({ challengeStatus: [] }); + + expect(db.query).toHaveBeenCalledWith("SELECT 1", [null, null, null, null]); + }); }); diff --git a/src/reports/challenges/challenges-reports.service.ts b/src/reports/challenges/challenges-reports.service.ts index df29539..d37a719 100644 --- a/src/reports/challenges/challenges-reports.service.ts +++ b/src/reports/challenges/challenges-reports.service.ts @@ -9,6 +9,10 @@ import { import { multiValueArrayFilter } from "src/common/filtering"; import { ChallengesReportResponseDto } from "./dtos/challenge.dto"; import { SubmissionLinksQueryDto } from "./dtos/submission-links.dto"; +import { + AiAssistedSubmissionDto, + AiAssistedSubmissionsQueryDto, +} from "./dtos/ai-assisted-submissions.dto"; import { ChallengeUserRecordDto, ChallengeUsersPathParamDto, @@ -44,6 +48,31 @@ export class ChallengesReportsService { } } + /** + * Retrieves submissions whose submitters answered the submit-page AI-usage question. + * @param filters Optional challenge, challenge status, and submission date filters. + * @returns One row per answered submission, newest first. + * @throws Propagates database errors so the request fails instead of returning a partial export. + */ + async getAiAssistedSubmissions( + filters: AiAssistedSubmissionsQueryDto, + ): Promise { + this.logger.debug( + "Starting getAiAssistedSubmissions with filters:", + filters, + ); + const query = this.sql.load( + "reports/challenges/ai-assisted-submissions.sql", + ); + + return this.db.query(query, [ + filters.challengeId ?? null, + filters.challengeStatus?.length ? filters.challengeStatus : null, + filters.submittedDateFrom ?? null, + filters.submittedDateTo ?? null, + ]); + } + async getChallengesReport(filters: ChallengeRegistrantsQueryDto) { this.logger.debug("Starting getChallengesReport with filters:", filters); diff --git a/src/reports/challenges/dtos/ai-assisted-submissions.dto.ts b/src/reports/challenges/dtos/ai-assisted-submissions.dto.ts new file mode 100644 index 0000000..7f6d644 --- /dev/null +++ b/src/reports/challenges/dtos/ai-assisted-submissions.dto.ts @@ -0,0 +1,91 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { + IsDateString, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; +import { Transform } from "class-transformer"; +import { transformArray } from "src/common/validation.util"; +import { ChallengeStatus } from "./challenge-status.enum"; + +/** Filters for the AI-assisted submissions report. All filters are optional. */ +export class AiAssistedSubmissionsQueryDto { + @ApiProperty({ + required: false, + description: "Only include submissions for this challenge ID", + }) + @IsOptional() + @IsString() + @IsNotEmpty() + challengeId?: string; + + @ApiProperty({ + required: false, + enum: ChallengeStatus, + example: [ChallengeStatus.ACTIVE, ChallengeStatus.COMPLETED], + isArray: true, + }) + @IsOptional() + @IsString({ each: true }) + @IsNotEmpty({ each: true }) + @Transform(transformArray) + challengeStatus?: ChallengeStatus[]; + + @ApiProperty({ + required: false, + description: "Only include submissions made on or after this date", + example: "2026-11-01T00:00:00.000Z", + }) + @IsOptional() + @IsDateString() + submittedDateFrom?: string; + + @ApiProperty({ + required: false, + description: "Only include submissions made on or before this date", + example: "2026-11-30T23:59:59.000Z", + }) + @IsOptional() + @IsDateString() + submittedDateTo?: string; +} + +/** One submission whose submitter answered the AI-usage question. */ +export class AiAssistedSubmissionDto { + @ApiProperty({ description: "Challenge ID" }) + challengeId: string; + + @ApiProperty({ description: "Challenge name" }) + challengeName: string; + + @ApiProperty({ description: "Challenge track name", nullable: true }) + challengeTrack: string | null; + + @ApiProperty({ description: "Challenge type name", nullable: true }) + challengeType: string | null; + + @ApiProperty({ description: "Challenge status", enum: ChallengeStatus }) + challengeStatus: ChallengeStatus; + + @ApiProperty({ description: "Submission ID" }) + submissionId: string; + + @ApiProperty({ description: "Submission type" }) + submissionType: string; + + @ApiProperty({ description: "Submitter member ID" }) + memberId: string; + + @ApiProperty({ description: "Submitter handle", nullable: true }) + submitterHandle: string | null; + + @ApiProperty({ + description: + "The submitter's answer: true when they reported that AI tools did most of the work", + }) + aiAssisted: boolean; + + @ApiProperty({ description: "Submission date" }) + submittedDate: string; +} diff --git a/src/reports/report-directory.data.ts b/src/reports/report-directory.data.ts index d5272d4..edc0e2e 100644 --- a/src/reports/report-directory.data.ts +++ b/src/reports/report-directory.data.ts @@ -223,6 +223,28 @@ const challengeHistoryFilters = [ ...challengeDateRangeParams, ]; +const aiAssistedSubmissionsFilters: ReportParameter[] = [ + { + name: "challengeId", + type: "string", + description: "Only include submissions for this challenge ID", + location: "query", + }, + challengeStatusParam, + { + name: "submittedDateFrom", + type: "date", + description: "Only include submissions made on or after this date", + location: "query", + }, + { + name: "submittedDateTo", + type: "date", + description: "Only include submissions made on or before this date", + location: "query", + }, +]; + const submissionLinksFilters = [ completionDateFromParam, completionDateToParam, @@ -418,17 +440,31 @@ const REGISTERED_REPORTS_DIRECTORY: RegisteredReportsDirectory = { win: { label: "WIN", basePath: "/WIN", - reports: [report( - "WIN showcases", - "/WIN", - "Showcase posts explicitly shared with WIN and their current project metadata.", - [AppScopes.WIN], - [ - { name: "projectId", type: "string", description: "Optional project ID." }, - { name: "page", type: "number", description: "Page number, starting at 1." }, - { name: "perPage", type: "number", description: "Page size, from 1 to 100." }, - ], - )], + reports: [ + report( + "WIN showcases", + "/WIN", + "Showcase posts explicitly shared with WIN and their current project metadata.", + [AppScopes.WIN], + [ + { + name: "projectId", + type: "string", + description: "Optional project ID.", + }, + { + name: "page", + type: "number", + description: "Page number, starting at 1.", + }, + { + name: "perPage", + type: "number", + description: "Page size, from 1 to 100.", + }, + ], + ), + ], }, challenges: { label: "Challenges Reports", @@ -483,6 +519,13 @@ const REGISTERED_REPORTS_DIRECTORY: RegisteredReportsDirectory = { AppScopes.Challenge.Winners, [challengeIdParam], ), + challengeReport( + "AI Assisted Submissions", + "/challenges/ai-assisted-submissions", + "Return every submission whose submitter answered the submit-page AI-usage question (Yes/No), with challenge track, type, and status. Submissions made before the question existed are not included.", + AppScopes.Challenge.AiAssistedSubmissions, + aiAssistedSubmissionsFilters, + ), ], }, identity: {