Skip to content
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

Test: Correct several format IDs #10633

Merged
merged 13 commits into from
Oct 29, 2024

Conversation

larry-the-table-guy
Copy link
Contributor

Found some instances where formats were being created w/ exists=false.
I made changes for the cases where a correct ID seemed obvious.
Those were:

  • gen6uber -> gen6ubers
  • gen7uber -> gen7ubers
  • gen9battlestadiumsingles -> gen9bssfactory (test label mentions factory)
  • gen5anythinggoes -> gen4anythinggoes (gen5 AG DNE)

Code for finding these
// top-level decls in ./sim/dex-formats.ts
const uniq_id = new Set();
const uniq_stack = new Set();

// ...

// inserted at bottom of Format constructor in ./sim/dex-formats.ts
if (!this.exists) {
        const stack = new Error().stack;
        if (!uniq_id.has(this.id) || !uniq_stack.has(stack)) {
                uniq_id.add(this.id);
                uniq_stack.add(stack);
                const ms = stack!.replace(/put-your-repo-path-here-or-comment-out/g, '.');
                console.log(`'${this.id}' : ${ms}`);
        }
}

Other instances of Formats where exists == false, may not be bugs.

Empty format names, seems intentional
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at Object.createBattle (./server/rooms.ts:2176:30)
    at Context.<anonymous> (./test/server/room-battle.js:27:17)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at GlobalRoomState.prepBattleRoom (./server/rooms.ts:1621:49)
    at Object.createBattle (./server/rooms.ts:2246:27)
    at Context.<anonymous> (./test/server/room-battle.js:27:17)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at new RoomBattle (./server/room-battle.ts:541:30)
    at Object.createBattle (./server/rooms.ts:2251:11)
    at Context.<anonymous> (./test/server/room-battle.js:27:17)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at new Battle (./sim/battle.ts:195:48)
    at RoomBattleStream._writeLine (./sim/battle-stream.ts:109:18)
    at RoomBattleStream._writeLines (./sim/battle-stream.ts:78:10)
    at RoomBattleStream._write (./server/room-battle.ts:1316:9)
    at RoomBattleStream.write (./lib/streams.ts:836:15)
    at new RoomBattle (./server/room-battle.ts:574:21)
    at Object.createBattle (./server/rooms.ts:2251:11)
    at Context.<anonymous> (./test/server/room-battle.js:27:17)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at new RoomBattleTimer (./server/room-battle.ts:191:30)
    at new RoomBattle (./server/room-battle.ts:599:16)
    at Object.createBattle (./server/rooms.ts:2251:11)
    at Context.<anonymous> (./test/server/room-battle.js:27:17)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at collectStats (./server/chat-plugins/randombattles/winrates.ts:176:29)
    at Object.onBattleEnd (./server/chat-plugins/randombattles/winrates.ts:169:8)
    at Object.runHandlers (./server/chat.ts:2083:11)
    at RoomBattle.end (./server/room-battle.ts:836:8)
    at RoomBattle.receive (./server/room-battle.ts:817:14)
    at RoomBattle.listen (./server/room-battle.ts:729:10)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
'gen8purehackmons'
'gen8purehackmons' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at new TeamValidator (./sim/team-validator.ts:325:29)
    at Function.get (./sim/team-validator.ts:2845:10)
    at Function.assert.legalTeam (./test/assert.js:51:69)
    at Context.<anonymous> (./test/sim/team-validator/basic.js:86:10)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'gen8purehackmons' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at new TeamValidator (./sim/team-validator.ts:325:29)
    at Function.get (./sim/team-validator.ts:2845:10)
    at Function.assert.legalTeam (./test/assert.js:51:69)
    at Context.<anonymous> (./test/sim/team-validator/basic.js:209:10)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary'
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.validateSet (./sim/team-validator.ts:619:34)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:416:60)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at Function.assert.legalTeam (./test/assert.js:51:81)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:95:10)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.validateSet (./sim/team-validator.ts:1050:34)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:416:60)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at Function.assert.legalTeam (./test/assert.js:51:81)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:95:10)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:469:34)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at Function.assert.legalTeam (./test/assert.js:51:81)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:95:10)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.validateSet (./sim/team-validator.ts:619:34)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:416:60)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at assert.legalTeam (./test/assert.js:51:81)
    at Function.assert.false.<computed> [as legalTeam] (./test/assert.js:258:23)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:101:16)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.validateSet (./sim/team-validator.ts:1050:34)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:416:60)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at assert.legalTeam (./test/assert.js:51:81)
    at Function.assert.false.<computed> [as legalTeam] (./test/assert.js:258:23)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:101:16)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'pokemontagrestrictedlegendary' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at TeamValidator.baseValidateTeam (./sim/team-validator.ts:469:34)
    at TeamValidator.validateTeam (./sim/team-validator.ts:345:15)
    at assert.legalTeam (./test/assert.js:51:81)
    at Function.assert.false.<computed> [as legalTeam] (./test/assert.js:258:23)
    at Context.<anonymous> (./test/sim/team-validator/custom-rules.js:101:16)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'gen9caprandombattle'
'gen9caprandombattle' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at ModdedDex.forFormat (./sim/dex.ts:178:28)
    at Suite.<anonymous> (./test/random-battles/all-gens.js:166:19)
    at Object.create (./node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (./node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (./test/random-battles/all-gens.js:116:1)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.exports.requireOrImport (./node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (./node_modules/mocha/lib/esm-utils.js:55:34)
    at singleRun (./node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (./node_modules/mocha/lib/cli/run.js:362:5)

'gen9caprandombattle' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at Teams2.getGenerator (./sim/teams.ts:620:24)
    at testTeam (./test/random-battles/tools.js:111:27)
    at Context.<anonymous> (./test/random-battles/all-gens.js:228:4)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)
'gen9caprandombattle' : Error: 
    at new Format (./sim/dex-formats.ts:502:18)
    at DexFormats.get (./sim/dex-formats.ts:698:13)
    at Teams2.getGenerator (./sim/teams.ts:620:24)
    at Context.<anonymous> (./test/random-battles/all-gens.js:233:28)
    at callFn (./node_modules/mocha/lib/runnable.js:366:21)
    at Test.Runnable.run (./node_modules/mocha/lib/runnable.js:354:5)
    at Runner.runTest (./node_modules/mocha/lib/runner.js:677:10)
    at ./node_modules/mocha/lib/runner.js:801:12
    at next (./node_modules/mocha/lib/runner.js:594:14)
    at ./node_modules/mocha/lib/runner.js:604:7
    at next (./node_modules/mocha/lib/runner.js:486:14)
    at Immediate._onImmediate (./node_modules/mocha/lib/runner.js:572:5)
    at processImmediate (node:internal/timers:476:21)

`gen5anythinggoes` is not defined. gen4 is the only AG format before gen6 (mega ray is the thing being tested)
@@ -163,7 +163,7 @@ describe('Mega Evolution', function () {
assertLegalButCantMega('gen9nationaldexag@@@-ndag');

// don't add it where unnecessary
assert.false(Dex.formats.getRuleTable(Dex.formats.get('gen5anythinggoes')).has('megarayquazaclause'));
assert.false(Dex.formats.getRuleTable(Dex.formats.get('gen4anythinggoes')).has('megarayquazaclause'));
Copy link
Contributor

@Slayer95 Slayer95 Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like Gen 5 AG, Gen 4 AG is not guaranteed to exist in the future.

Can you fix this in a more reliable way?

Even just assert(Dex.formats.get('gen4anythinggoes').exists) can do the trick, so that this test gets properly updated if/when Gen 4 AG is deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, made the change suggested in the later comment.

The code would now get this error message:

  2690 passing (5m)
  90 pending
  1 failing

  1) Mega Evolution
       Mega Rayquaza
         should implicitly add the Mega Rayquaza Clause when banned:
     Error: Unidentified format: gen5anythinggoes
      at TestTools.getFormat (test/common.js:47:30)
      at Context.<anonymous> (test/sim/misc/megaevolution.js:166:26)
      at processImmediate (node:internal/timers:476:21)


The other two instances of formats.get don't seem like they should / need to be changed.

$ grep -rn "formats.get(" ./test/
./test/random-battles/all-gens.js:31:	const format = Dex.formats.get(`${formatID}@@@Max Move Count = ${count}`);
./test/sim/team-validator/basic.js:11:	Dex.formats.getRuleTable(Dex.formats.get(format));
./test/common.js:46:	const format = Dex.formats.get(options.formatid);
./test/common.js:79:	format = Dex.formats.get(formatName);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar for helpers that wrap TeamValidator.get(), probably?

function validateLearnset(move, set, tier, mod = 'gen8') {
const validator = TeamValidator.get(`${mod}${tier}`);

if (!validator.format.exists) ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about checking format.exists in the TeamValidator constructor?
My understanding is that if you reached this path in the Format constructor, then you get an empty ruletable, which probably isn't interesting for team validation.

I suppose someone could construct a populated Format and add an exists: false property, but I don't see why they would knowingly do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Except that I have just remembered that format.exists is often a useless flag. format.effectType == 'Format' should be checked instead, to distinguish actual formats from rulesets. Other commits might need adjustments accordingly.

Copy link
Contributor

@Slayer95 Slayer95 Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition is PS's equivalent to JavaScript's Object. In JS, everything is an Object. In PS, everything is a Condition (formerly called Effect). Given the ambiguity between formats, rulesets, and other stuff, Condition is indeed fitting. The Condition semantics are further elaborated by the fact that Format and Ruleset may and often include event handlers.

Of course, this is likely surprising for many, but it's a direct consequence of the design or lack thereof of PS format system (not favoring either side, I can see the benefits of the current system, though certainly it can be improved).

Also, these lines at dex-formats.ts don't help, which are certainly incorrect:

type FormatEffectType = 'Format' | 'Ruleset' | 'Rule' | 'ValidatorRule';
this.effectType = Utils.getString(data.effectType) as FormatEffectType || 'Format';

Having said all that, I did forget these facts at the time of reading your quiz, because I have actually been a very inactive contributor. But, hey, that was the reason why I remembered and suggested that we should just check that effectType is 'Format'. It's indeed enough ;D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Since you are interested in the findEventHandlers situation, that link should be very useful to you.

Copy link
Contributor Author

@larry-the-table-guy larry-the-table-guy Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I looked and it seems that the effectType convention for invalid Formats dates back to the start of the repo and the introduction of getFormat. Ah well. I just feel bad for the next person who has to infer why a Format sometimes isn't a 'Format'.


I ended up going with common.getFormat because that would have caught the expired CAP case, and gen9baby isn't a mod so common.mod would crash.

Original
for (const format of Object.keys(formatInfo)) {
        const filename = formatInfo[format].filename;
        const setsJSON = require(`../../dist/data/random-battles/${filename}.json`);
        const mod = filename.split('/')[0];
        const genNum = parseInt(mod[3]);
        const rounds = 100;
        const dex = Dex.forFormat(format);
        console.log(format, genNum, dex.gen);

=>

gen2randombattle 2 2
gen3randombattle 3 3
gen4randombattle 4 4
gen5randombattle 5 5
gen6randombattle 6 6
gen7randombattle 7 7
gen9randombattle 9 9
gen9randomdoublesbattle 9 9
gen9babyrandombattle 9 9

v2 (to demonstrate footgun in getFormat)
for (const format of Object.keys(formatInfo)) {
        const filename = formatInfo[format].filename;
        const setsJSON = require(`../../dist/data/random-battles/${filename}.json`);
        const dex = common.mod(common.getFormat(format).mod).dex; // .getFormat verifies format exists
        console.log(format, dex.gen);
        const rounds = 100;

=>

gen2randombattle 9
gen3randombattle 9
gen4randombattle 9
gen5randombattle 9
gen6randombattle 9
gen7randombattle 9
gen9randombattle 9
gen9randomdoublesbattle 9
gen9babyrandombattle 9

Fails in a very non-obvious fashion.


v3
for (const format of Object.keys(formatInfo)) {
        const filename = formatInfo[format].filename;
        const setsJSON = require(`../../dist/data/random-battles/${filename}.json`);
        const dex = common.mod(common.getFormat({formatid: format}).mod).dex; // verifies format exists
        const genNum = dex.gen;
        console.log(format, genNum);
        const rounds = 100;

=>

gen2randombattle 2
gen3randombattle 3
gen4randombattle 4
gen5randombattle 5
gen6randombattle 6
gen7randombattle 7
gen9randombattle 9
gen9randomdoublesbattle 9
gen9babyrandombattle 9

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to use v3 if you prefer it. But it looks like common.mod should also be calling loadData() itself. I am not sure what the state of your other PRs is, so maybe that can be done later, to avoid conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are still doing archaeology, I tracked the gen loading issue to 3716f36.

This basically means you don't need to do Tools.includeData() or anything like that anymore

Is TypeScript full of void promises??!

@Slayer95
Copy link
Contributor

Slayer95 commented Oct 26, 2024

Best forwards-safe fix would be to migrate to common.getFormat({formatid}), while also patching this function so that it always throws if the given format does not exist.

@Slayer95
Copy link
Contributor

Slayer95 commented Oct 26, 2024

'gen8purehackmons'

Format is Pure Hackmons nowadays.

'pokemontagrestrictedlegendary' : Error:

I think team-validator.ts:469,618,etc should also guard against tag marker *.

'gen9caprandombattle'

Can this test or this part of the test be skipped?

@@ -372,7 +380,7 @@ describe('[Gen 9] BSS Factory data should be valid (slow)', () => {
const genNum = 9;

for (const speciesid in setsJSON) {
const vType = 'battlestadiumsingles';
const vType = 'bssfactory';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be bssregh, since it's validating off of the base battle stadium format legality. Obviously a fix of checking if gen9bssregh exists would make sure people update this since there's no easy way to automate this apart from trying to assign an alias to the BSS format that's active in aliases.ts, but if you can figure something else out I'm all ears.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I could come up with so far is validating that the formats exist. The alias is an interesting idea, kind of like how 'base' is an alias for the current gen's dex.

@larry-the-table-guy
Copy link
Contributor Author

'gen8purehackmons'

Format is Pure Hackmons nowadays.

I'll take this to mean gen9purehackmons.
I don't know whether I should also change the nearby AG lines as well for consistency.

        it(`should enforce the 3 perfect IV minimum on legendaries with Gen 6+ origin`, function () {
                const team = [
                        {species: 'xerneas', ability: 'fairyaura', moves: ['snore'], ivs: {hp: 0, atk: 0, def: 0, spa: 0}, evs: {hp: 1}},
                ];
                assert.false.legalTeam(team, 'gen8anythinggoes');

                assert.legalTeam(team, 'gen9purehackmons');
        });

'pokemontagrestrictedlegendary' : Error:

I think team-validator.ts:469,618,etc should also guard against tag marker *.

👍


'gen9caprandombattle'

Can this test or this part of the test be skipped?

Looks like the format was removed a few commits ago, so I removed the test case.

@KrisXV
Copy link
Member

KrisXV commented Oct 28, 2024

Looks like the format was removed a #10522, so I removed the test case.

The format is still playable by challenging a user to gen9randombattle@@@+cap I believe, so surely the test can just be changed to this?

@Zarel
Copy link
Member

Zarel commented Oct 29, 2024

Looks good, thanks!

@Zarel Zarel merged commit 71fe7bd into smogon:master Oct 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants