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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 ----
Expand Down Expand Up @@ -38,7 +38,7 @@
# 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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/c2df92b2227089909ab6e229df0ec6b658bb431a"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
Expand Down
37 changes: 19 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions sql/reports/challenges/ai-assisted-submissions.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/app-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -70,6 +71,7 @@ export const ScopeRoleAccess: Record<string, readonly string[]> = {
[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,
Expand Down
10 changes: 10 additions & 0 deletions src/reports/challenges/challenge-export-sql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
});
});
23 changes: 23 additions & 0 deletions src/reports/challenges/challenges-reports.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<AiAssistedSubmissionDto[]>,
})
async getAiAssistedSubmissions(
@Query() query: AiAssistedSubmissionsQueryDto,
) {
return this.reportsService.getAiAssistedSubmissions(query);
}

@Get("/:challengeId/registered-users")
@UseGuards(PermissionsGuard)
@Scopes(AppScopes.AllReports, AppScopes.Challenge.RegisteredUsers)
Expand Down
44 changes: 44 additions & 0 deletions src/reports/challenges/challenges-reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});
29 changes: 29 additions & 0 deletions src/reports/challenges/challenges-reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AiAssistedSubmissionDto[]> {
this.logger.debug(
"Starting getAiAssistedSubmissions with filters:",
filters,
);
const query = this.sql.load(
"reports/challenges/ai-assisted-submissions.sql",
);

return this.db.query<AiAssistedSubmissionDto>(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);

Expand Down
Loading
Loading