-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(parser): respect escape for timestamp syntax #39457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IsseiHasegawa
wants to merge
8
commits into
RocketChat:develop
Choose a base branch
from
IsseiHasegawa:test/message-parser-first-pr
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c6dff5
Add strike test for relative timestamp format
IsseiHasegawa f357ecf
test: add property-based fuzz tests for message parser
IsseiHasegawa f9512e1
fix: respect escape for timestamp syntax
IsseiHasegawa 084805e
fix(parser): preserve escaped timestamp literals
IsseiHasegawa ff4fc46
Merge branch 'develop' into test/message-parser-first-pr
IsseiHasegawa d63415d
Save local changes to yarn.lock
IsseiHasegawa 1ed6985
Add fast-check to message-parser package
IsseiHasegawa 7212c3b
test: add coverage for SchedulerModify accessor
IsseiHasegawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
packages/apps-engine/tests/server/accessors/SchedulerModify.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import { AsyncTest, Expect, SetupFixture } from 'alsatian'; | ||
|
|
||
| import type { IOnetimeSchedule, IRecurringSchedule } from '../../../src/definition/scheduler'; | ||
| import { SchedulerModify } from '../../../src/server/accessors'; | ||
| import type { SchedulerBridge } from '../../../src/server/bridges'; | ||
|
|
||
| export class SchedulerModifyAccessorTestFixture { | ||
| private mockSchedulerBridge: SchedulerBridge; | ||
|
|
||
| private scheduleOnceCalls: Array<{ job: IOnetimeSchedule; appId: string }>; | ||
|
|
||
| private scheduleRecurringCalls: Array<{ job: IRecurringSchedule; appId: string }>; | ||
|
|
||
| private cancelJobCalls: Array<{ jobId: string; appId: string }>; | ||
|
|
||
| private cancelAllJobsCalls: string[]; | ||
|
|
||
| @SetupFixture | ||
| public setupFixture(): void { | ||
| this.scheduleOnceCalls = []; | ||
| this.scheduleRecurringCalls = []; | ||
| this.cancelJobCalls = []; | ||
| this.cancelAllJobsCalls = []; | ||
|
|
||
| const { scheduleOnceCalls, scheduleRecurringCalls, cancelJobCalls, cancelAllJobsCalls } = this; | ||
|
|
||
| this.mockSchedulerBridge = { | ||
| doScheduleOnce(job: IOnetimeSchedule, appId: string): Promise<void> { | ||
| scheduleOnceCalls.push({ job, appId }); | ||
| return Promise.resolve(); | ||
| }, | ||
| doScheduleRecurring(job: IRecurringSchedule, appId: string): Promise<void> { | ||
| scheduleRecurringCalls.push({ job, appId }); | ||
| return Promise.resolve(); | ||
| }, | ||
| doCancelJob(jobId: string, appId: string): Promise<void> { | ||
| cancelJobCalls.push({ jobId, appId }); | ||
| return Promise.resolve(); | ||
| }, | ||
| doCancelAllJobs(appId: string): Promise<void> { | ||
| cancelAllJobsCalls.push(appId); | ||
| return Promise.resolve(); | ||
| }, | ||
| } as SchedulerBridge; | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async scheduleOnceAppendsAppIdWhenMissing(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
| const job: IOnetimeSchedule = { | ||
| id: 'job-1', | ||
| when: new Date('2026-03-24T12:00:00.000Z'), | ||
| data: { pollId: '123' }, | ||
| }; | ||
|
|
||
| await Expect(() => scheduler.scheduleOnce(job)).not.toThrowAsync(); | ||
|
|
||
| Expect(this.scheduleOnceCalls.length).toBe(1); | ||
| Expect(this.scheduleOnceCalls[0].appId).toBe('test-app'); | ||
| Expect(this.scheduleOnceCalls[0].job).toEqual({ | ||
| ...job, | ||
| id: 'job-1_test-app', | ||
| }); | ||
| Expect(job.id).toBe('job-1'); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async scheduleOnceDoesNotAppendAppIdTwice(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
| const job: IOnetimeSchedule = { | ||
| id: 'job-1_test-app', | ||
| when: 'in 5 minutes', | ||
| }; | ||
|
|
||
| await scheduler.scheduleOnce(job); | ||
|
|
||
| Expect(this.scheduleOnceCalls.length).toBe(1); | ||
| Expect(this.scheduleOnceCalls[0].job.id).toBe('job-1_test-app'); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async scheduleRecurringAppendsAppIdWhenMissing(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
| const job: IRecurringSchedule = { | ||
| id: 'recurring-1', | ||
| interval: '5 minutes', | ||
| skipImmediate: true, | ||
| data: { roomId: 'abc' }, | ||
| }; | ||
|
|
||
| await scheduler.scheduleRecurring(job); | ||
|
|
||
| Expect(this.scheduleRecurringCalls.length).toBe(1); | ||
| Expect(this.scheduleRecurringCalls[0].appId).toBe('test-app'); | ||
| Expect(this.scheduleRecurringCalls[0].job).toEqual({ | ||
| ...job, | ||
| id: 'recurring-1_test-app', | ||
| }); | ||
| Expect(job.id).toBe('recurring-1'); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async cancelJobAppendsAppIdWhenMissing(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
|
|
||
| await scheduler.cancelJob('cleanup-job'); | ||
|
|
||
| Expect(this.cancelJobCalls.length).toBe(1); | ||
| Expect(this.cancelJobCalls[0]).toEqual({ | ||
| jobId: 'cleanup-job_test-app', | ||
| appId: 'test-app', | ||
| }); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async cancelJobDoesNotAppendAppIdTwice(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
|
|
||
| await scheduler.cancelJob('cleanup-job_test-app'); | ||
|
|
||
| Expect(this.cancelJobCalls.length).toBe(1); | ||
| Expect(this.cancelJobCalls[0]).toEqual({ | ||
| jobId: 'cleanup-job_test-app', | ||
| appId: 'test-app', | ||
| }); | ||
| } | ||
|
|
||
| @AsyncTest() | ||
| public async cancelAllJobsUsesOnlyAppId(): Promise<void> { | ||
| const scheduler = new SchedulerModify(this.mockSchedulerBridge, 'test-app'); | ||
|
|
||
| await scheduler.cancelAllJobs(); | ||
|
|
||
| Expect(this.cancelAllJobsCalls.length).toBe(1); | ||
| Expect(this.cancelAllJobsCalls[0]).toBe('test-app'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import fc from 'fast-check'; | ||
|
|
||
| import { parse } from '../src'; | ||
|
|
||
| const plainTextArbitrary = fc | ||
| .stringMatching(/[a-zA-Z0-9 ]{1,20}/) | ||
| .filter((value) => value.length > 0); | ||
|
|
||
| const timestampArbitrary = fc | ||
| .integer({ min: 1_000_000_000, max: 2_000_000_000 }) | ||
| .map((value) => `<t:${value}>`); | ||
|
|
||
| const relativeTimestampArbitrary = fc | ||
| .integer({ min: 1_000_000_000, max: 2_000_000_000 }) | ||
| .map((value) => `<t:${value}:R>`); | ||
|
|
||
| const mentionArbitrary = fc | ||
| .stringMatching(/[a-z0-9._-]{1,12}/) | ||
| .map((value) => `@${value}`); | ||
|
|
||
| const boldArbitrary = plainTextArbitrary.map((value) => `*${value}*`); | ||
|
|
||
| const strikeArbitrary = fc.oneof(timestampArbitrary, relativeTimestampArbitrary, plainTextArbitrary).map((value) => `~${value}~`); | ||
|
|
||
| const inlineCodeArbitrary = plainTextArbitrary.map((value) => `\`${value}\``); | ||
|
|
||
| const parserInputArbitrary = fc | ||
| .array( | ||
| fc.oneof( | ||
| plainTextArbitrary, | ||
| timestampArbitrary, | ||
| relativeTimestampArbitrary, | ||
| mentionArbitrary, | ||
| boldArbitrary, | ||
| strikeArbitrary, | ||
| inlineCodeArbitrary, | ||
| ), | ||
| { minLength: 1, maxLength: 8 }, | ||
| ) | ||
| .map((parts) => parts.join(' ')); | ||
|
|
||
| describe('parser fuzz tests', () => { | ||
| test('parses valid parser-like inputs without throwing', () => { | ||
| fc.assert( | ||
| fc.property(parserInputArbitrary, (input) => { | ||
| expect(() => parse(input)).not.toThrow(); | ||
| }), | ||
| { numRuns: 300 }, | ||
| ); | ||
| }); | ||
|
|
||
| test('is deterministic for valid parser-like inputs', () => { | ||
| fc.assert( | ||
| fc.property(parserInputArbitrary, (input) => { | ||
| expect(parse(input)).toEqual(parse(input)); | ||
| }), | ||
| { numRuns: 300 }, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.