forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(twitter): allow leading numbers and wildcard in target usernames
Fix for elizaOS#1556 - Added support for Twitter usernames starting with numbers - Added support for wildcard '*' in TWITTER_TARGET_USERS - Fixed test discovery in test.sh to find all .test.ts files - Updated Jest config for better ESM support The main change allows Twitter target usernames to start with numbers and use wildcards, matching current Twitter/X username rules. Test infrastructure was improved to properly handle ESM modules and find all test files. Changes: - Updated username validation regex in Twitter client - Added test cases for numeric usernames and wildcards - Switched test.sh to use find for reliable test discovery - Simplified Jest config to focus on ESM support
- Loading branch information
Showing
7 changed files
with
192 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
{ | ||
"testEnvironment": "node", | ||
"extensionsToTreatAsEsm": [".ts"], | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"ts-jest", | ||
{ | ||
"useESM": true, | ||
"tsconfig": { | ||
"module": "esnext", | ||
"target": "esnext", | ||
"moduleResolution": "bundler" | ||
} | ||
} | ||
] | ||
}, | ||
"moduleNameMapper": { | ||
"^@elizaos/core$": "<rootDir>/packages/core/src/index.ts", | ||
"^@elizaos/(.*)$": "<rootDir>/packages/$1/src/index.ts" | ||
} | ||
} |
This file contains 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 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,67 @@ | ||
import { twitterEnvSchema } from "../environment"; | ||
|
||
describe("Twitter Environment Configuration", () => { | ||
describe("Username Validation", () => { | ||
const validateUsername = (username: string) => { | ||
return twitterEnvSchema.parse({ | ||
TWITTER_DRY_RUN: false, | ||
TWITTER_USERNAME: "test_user", | ||
TWITTER_PASSWORD: "password", | ||
TWITTER_EMAIL: "[email protected]", | ||
TWITTER_2FA_SECRET: "", | ||
TWITTER_RETRY_LIMIT: 5, | ||
TWITTER_POLL_INTERVAL: 120, | ||
POST_INTERVAL_MIN: 90, | ||
POST_INTERVAL_MAX: 180, | ||
ENABLE_ACTION_PROCESSING: false, | ||
ACTION_INTERVAL: 5, | ||
POST_IMMEDIATELY: false, | ||
TWITTER_TARGET_USERS: [username], | ||
}); | ||
}; | ||
|
||
it("should allow valid traditional usernames", () => { | ||
expect(() => validateUsername("normal_user")).not.toThrow(); | ||
expect(() => validateUsername("user123")).not.toThrow(); | ||
expect(() => validateUsername("a_1_b_2")).not.toThrow(); | ||
}); | ||
|
||
it("should allow usernames starting with digits", () => { | ||
expect(() => validateUsername("123user")).not.toThrow(); | ||
expect(() => validateUsername("42_test")).not.toThrow(); | ||
expect(() => validateUsername("007james")).not.toThrow(); | ||
}); | ||
|
||
it("should allow wildcard", () => { | ||
expect(() => validateUsername("*")).not.toThrow(); | ||
}); | ||
|
||
it("should reject invalid usernames", () => { | ||
expect(() => validateUsername("")).toThrow(); | ||
expect(() => validateUsername("user@123")).toThrow(); | ||
expect(() => validateUsername("user-123")).toThrow(); | ||
expect(() => validateUsername("user.123")).toThrow(); | ||
expect(() => validateUsername("a".repeat(16))).toThrow(); | ||
}); | ||
|
||
it("should handle array of usernames", () => { | ||
const config = { | ||
TWITTER_DRY_RUN: false, | ||
TWITTER_USERNAME: "test_user", | ||
TWITTER_PASSWORD: "password", | ||
TWITTER_EMAIL: "[email protected]", | ||
TWITTER_2FA_SECRET: "", | ||
TWITTER_RETRY_LIMIT: 5, | ||
TWITTER_POLL_INTERVAL: 120, | ||
POST_INTERVAL_MIN: 90, | ||
POST_INTERVAL_MAX: 180, | ||
ENABLE_ACTION_PROCESSING: false, | ||
ACTION_INTERVAL: 5, | ||
POST_IMMEDIATELY: false, | ||
TWITTER_TARGET_USERS: ["normal_user", "123digit", "*"], | ||
}; | ||
|
||
expect(() => twitterEnvSchema.parse(config)).not.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
"forceConsistentCasingInFileNames": true, | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true | ||
}, | ||
"files": [], | ||
"references": [ | ||
{ "path": "packages/core" }, | ||
{ "path": "packages/client-slack" } | ||
{ | ||
"path": "packages/core" | ||
}, | ||
{ | ||
"path": "packages/client-slack" | ||
} | ||
] | ||
} | ||
} |