opcn1214-generator: cg.improvements.expense compares raw floats, so a valid report can fail to generate

オープン 初心者向け
#5,257 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
backend

調査の方向性

まず packages/opcn1214-generator/src/validate/capital-gains-rules.ts:178 を開き、shareholders.dividendRights.total にある既存の百分の一単位の比較を調べてください。減価償却のテストを更新して 14.46 + 49.59 + 35.95 を含め、その後 src/validate/ を検索して、金額を浮動小数点数のまま直接比較している箇所を探してください。回帰テストが成功し、そのディレクトリに金額を浮動小数点数のまま直接比較している箇所がほかにない状態が完了条件です。

索引モデルが issue の本文から書いたものです。

説明

1214 annual-audit-workflow

Problem

packages/opcn1214-generator/src/validate/capital-gains-rules.ts:178, in cg.improvements.expense:

if (typeof depreciation === 'number' && depreciation > expense) {

This compares raw doubles, so float residue decides the result. A depreciation summed in JS can land just above the expense: 14.46 + 49.59 + 35.95 is 100.00000000000001.

Repro: a 3077 improvement with expense: 100 and accumulatedDepreciation: 14.46 + 49.59 + 35.95.

  • field.decimals accepts the value. The file would hold 000000010000 for both amounts (10000 hundredths each).
  • validate1214 reports cg.improvements.expense: "Improvement 1 has an accumulated depreciation (100.00000000000001) above its expense (100)." So generate1214 throws Opcn1214ValidationError.
  • The file written for accumulatedDepreciation: 100 is byte-identical, and parse1214 of it reports nothing.

So validating the input and parsing the file disagree, and a fully depreciated improvement can block generation.

Fix

Compare in hundredths, as written to the file. shareholders.dividendRights.total already does this:

// Compared in hundredths, as written to the file: 14.46 + 49.59 + 35.95 is above 100.
if (
  typeof depreciation === 'number' &&
  Math.round(depreciation * 100) > Math.round(expense * 100)
) {

Done when

  • The comparison works in hundredths.
  • The test "accepts a depreciation equal to the expense…" includes the 14.46 + 49.59 + 35.95 vector.
  • No other amount comparison in src/validate/ compares raw doubles. The same kind of bug came up in several places during the stack review.

Raised in the review of #5081 (FIX-3), which added this rule. The review wasn't posted because the PR merged first. Re-checked on main at 31245bc7f.

主要言語
TypeScript
スター
30
フォーク
10
平均マージ
2日 12時間
マージ済み PR(30日)
276

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Urigo/accounter-fullstack のほかの issue

Urigo/accounter-fullstack の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。